how to dynamically add images to UI from code behind asp.net with all the styles already declared in .aspx pageGet URL of ASP.Net Page in code-behindQuestion about inline aspx tagshow to access the dynamically created HTML control from code behind in asp.netHow to access non-asp <img> tag from code behind?possible to reference CSS selector in code-behind ASP.NETHow to define height of a container by an element within that containerList with images from code behind (ASP.NET C#) to image overview in ASPXHow to select a div element in the code-behind page?How to remove dynamicaly created <div> tag if img src='undefined' in asp.net C#?Cannot display HTML string
Why didn't NASA launch communications relay satellites for the Apollo missions?
Aren't all schwa sounds literally /ø/?
Why do we need an estimator to be consistent?
How does the Gameboy's memory bank switching work?
What is the intuition for higher homotopy groups not vanishing?
What does a Nintendo Game Boy do when turned on without a game cartridge inserted?
Why didn't Balak request Bilam to bless his own people?
Why would word of Princess Leia's capture generate sympathy for the Rebellion in the Senate?
Satellite in orbit in front of and behind the Moon
Why is there an extra "t" in Lemmatization?
Nilpotent elements of Lie algebra and unipotent groups
Do you need to have the original move to take a "Replaces:" move?
Do pedestrians imitate automotive traffic?
Is art a form of communication?
Router restarts after big git push or big file upload
ESTA Travel not Authorized. Accepted twice before!
Could a US citizen born through "birth tourism" become President?
Do we have to introduce the character's name before using their names in a dialogue tag?
Discretisation of region intersection in 3D
Found old paper shares of Motorola Inc that has since been broken up
Linux ext4 restore file and directory access rights after bad backup/restore
You have no, but can try for yes
"move up the school" meaning
Counting multiples of 3 up to a given number
how to dynamically add images to UI from code behind asp.net with all the styles already declared in .aspx page
Get URL of ASP.Net Page in code-behindQuestion about inline aspx tagshow to access the dynamically created HTML control from code behind in asp.netHow to access non-asp <img> tag from code behind?possible to reference CSS selector in code-behind ASP.NETHow to define height of a container by an element within that containerList with images from code behind (ASP.NET C#) to image overview in ASPXHow to select a div element in the code-behind page?How to remove dynamicaly created <div> tag if img src='undefined' in asp.net C#?Cannot display HTML string
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have developed a aspx page statically where the code is like
<div class="container">
<div class="contain" id="subdiv" runat="server">
<input type="checkbox" id="cb1" runat="server" />
<label for="cb1">
<img src="Images/download_image.jfif" runat="server" id="imagesrc"/>
<label>some text</label>
</label>
</div>
</div>
For now I gave only one image in UI and trying to increase the count manually like below
for (int i = 0; i <= 5; i++)
Image img = new Image();
img.ImageUrl = "~/Images/download_image.jfif";
subdiv.Controls.Add(img);
the code i am trying is not working.
it is like images acting like checkboxes with a label caption.But the number of images depends on the data coming from a sql table and the image for all are same.How can i call the image which is inside of div element and display it based on the count times from code behind so that all the css and js script will be applied .Please help me
javascript html css asp.net
add a comment |
I have developed a aspx page statically where the code is like
<div class="container">
<div class="contain" id="subdiv" runat="server">
<input type="checkbox" id="cb1" runat="server" />
<label for="cb1">
<img src="Images/download_image.jfif" runat="server" id="imagesrc"/>
<label>some text</label>
</label>
</div>
</div>
For now I gave only one image in UI and trying to increase the count manually like below
for (int i = 0; i <= 5; i++)
Image img = new Image();
img.ImageUrl = "~/Images/download_image.jfif";
subdiv.Controls.Add(img);
the code i am trying is not working.
it is like images acting like checkboxes with a label caption.But the number of images depends on the data coming from a sql table and the image for all are same.How can i call the image which is inside of div element and display it based on the count times from code behind so that all the css and js script will be applied .Please help me
javascript html css asp.net
have a look at repeaters and how to use a prepeater
– Pete
Mar 26 at 12:39
better to use any of these controls like GridView, ListView or Repeater .. other waay around use 'subdiv.controls.add(img)' in side loop.
– Neeraj Kumar Gupta
Mar 26 at 12:49
The image is same for all the data that is coming from the table and should be displayed side by side and also associated with an url which downloads respective file associated with the data
– Sravani Chinta
Mar 26 at 12:57
add a comment |
I have developed a aspx page statically where the code is like
<div class="container">
<div class="contain" id="subdiv" runat="server">
<input type="checkbox" id="cb1" runat="server" />
<label for="cb1">
<img src="Images/download_image.jfif" runat="server" id="imagesrc"/>
<label>some text</label>
</label>
</div>
</div>
For now I gave only one image in UI and trying to increase the count manually like below
for (int i = 0; i <= 5; i++)
Image img = new Image();
img.ImageUrl = "~/Images/download_image.jfif";
subdiv.Controls.Add(img);
the code i am trying is not working.
it is like images acting like checkboxes with a label caption.But the number of images depends on the data coming from a sql table and the image for all are same.How can i call the image which is inside of div element and display it based on the count times from code behind so that all the css and js script will be applied .Please help me
javascript html css asp.net
I have developed a aspx page statically where the code is like
<div class="container">
<div class="contain" id="subdiv" runat="server">
<input type="checkbox" id="cb1" runat="server" />
<label for="cb1">
<img src="Images/download_image.jfif" runat="server" id="imagesrc"/>
<label>some text</label>
</label>
</div>
</div>
For now I gave only one image in UI and trying to increase the count manually like below
for (int i = 0; i <= 5; i++)
Image img = new Image();
img.ImageUrl = "~/Images/download_image.jfif";
subdiv.Controls.Add(img);
the code i am trying is not working.
it is like images acting like checkboxes with a label caption.But the number of images depends on the data coming from a sql table and the image for all are same.How can i call the image which is inside of div element and display it based on the count times from code behind so that all the css and js script will be applied .Please help me
javascript html css asp.net
javascript html css asp.net
edited Mar 26 at 12:50
Sravani Chinta
asked Mar 26 at 12:36
Sravani ChintaSravani Chinta
419 bronze badges
419 bronze badges
have a look at repeaters and how to use a prepeater
– Pete
Mar 26 at 12:39
better to use any of these controls like GridView, ListView or Repeater .. other waay around use 'subdiv.controls.add(img)' in side loop.
– Neeraj Kumar Gupta
Mar 26 at 12:49
The image is same for all the data that is coming from the table and should be displayed side by side and also associated with an url which downloads respective file associated with the data
– Sravani Chinta
Mar 26 at 12:57
add a comment |
have a look at repeaters and how to use a prepeater
– Pete
Mar 26 at 12:39
better to use any of these controls like GridView, ListView or Repeater .. other waay around use 'subdiv.controls.add(img)' in side loop.
– Neeraj Kumar Gupta
Mar 26 at 12:49
The image is same for all the data that is coming from the table and should be displayed side by side and also associated with an url which downloads respective file associated with the data
– Sravani Chinta
Mar 26 at 12:57
have a look at repeaters and how to use a prepeater
– Pete
Mar 26 at 12:39
have a look at repeaters and how to use a prepeater
– Pete
Mar 26 at 12:39
better to use any of these controls like GridView, ListView or Repeater .. other waay around use 'subdiv.controls.add(img)' in side loop.
– Neeraj Kumar Gupta
Mar 26 at 12:49
better to use any of these controls like GridView, ListView or Repeater .. other waay around use 'subdiv.controls.add(img)' in side loop.
– Neeraj Kumar Gupta
Mar 26 at 12:49
The image is same for all the data that is coming from the table and should be displayed side by side and also associated with an url which downloads respective file associated with the data
– Sravani Chinta
Mar 26 at 12:57
The image is same for all the data that is coming from the table and should be displayed side by side and also associated with an url which downloads respective file associated with the data
– Sravani Chinta
Mar 26 at 12:57
add a comment |
1 Answer
1
active
oldest
votes
if you are going to read from database you should use OdbcCommand and the code as follows
using (OdbcCommand cmd = new OdbcCommand(yourquery, cn))
using (OdbcDataReader reader = cmd.ExecuteReader())
var divHtml = new System.Text.StringBuilder();
while (reader.Read())
System.Web.UI.HtmlControls.HtmlGenericControl div = new
System.Web.UI.HtmlControls.HtmlGenericControl("div");
div.ID = "div";
div.InnerHtml = String.Format("0", reader.GetString(0));
Image img = new Image();
img.ImageUrl = "~/Images/download_image.jfif";
img.AlternateText = "Dynamic Images";
div.Controls.Add(img);
divHtml.append(div);
subdiv.InnerHtml = divHtml.ToString();
I have defined js and css for div and check box elements in .aspx page.Will it be applied to the adding image and div elements for the above mentioned code.
– Sravani Chinta
Mar 26 at 13:16
this code contains a div control thus you can add anything to it, but if you want to take actions on checkboxes and other elements I advise to use javascript and send and receive data to server using ajax
– AhmadMM
Mar 26 at 13:18
if you found it useful, don't forget to mark it as an answer ;)
– AhmadMM
Mar 26 at 13:24
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55357373%2fhow-to-dynamically-add-images-to-ui-from-code-behind-asp-net-with-all-the-styles%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
if you are going to read from database you should use OdbcCommand and the code as follows
using (OdbcCommand cmd = new OdbcCommand(yourquery, cn))
using (OdbcDataReader reader = cmd.ExecuteReader())
var divHtml = new System.Text.StringBuilder();
while (reader.Read())
System.Web.UI.HtmlControls.HtmlGenericControl div = new
System.Web.UI.HtmlControls.HtmlGenericControl("div");
div.ID = "div";
div.InnerHtml = String.Format("0", reader.GetString(0));
Image img = new Image();
img.ImageUrl = "~/Images/download_image.jfif";
img.AlternateText = "Dynamic Images";
div.Controls.Add(img);
divHtml.append(div);
subdiv.InnerHtml = divHtml.ToString();
I have defined js and css for div and check box elements in .aspx page.Will it be applied to the adding image and div elements for the above mentioned code.
– Sravani Chinta
Mar 26 at 13:16
this code contains a div control thus you can add anything to it, but if you want to take actions on checkboxes and other elements I advise to use javascript and send and receive data to server using ajax
– AhmadMM
Mar 26 at 13:18
if you found it useful, don't forget to mark it as an answer ;)
– AhmadMM
Mar 26 at 13:24
add a comment |
if you are going to read from database you should use OdbcCommand and the code as follows
using (OdbcCommand cmd = new OdbcCommand(yourquery, cn))
using (OdbcDataReader reader = cmd.ExecuteReader())
var divHtml = new System.Text.StringBuilder();
while (reader.Read())
System.Web.UI.HtmlControls.HtmlGenericControl div = new
System.Web.UI.HtmlControls.HtmlGenericControl("div");
div.ID = "div";
div.InnerHtml = String.Format("0", reader.GetString(0));
Image img = new Image();
img.ImageUrl = "~/Images/download_image.jfif";
img.AlternateText = "Dynamic Images";
div.Controls.Add(img);
divHtml.append(div);
subdiv.InnerHtml = divHtml.ToString();
I have defined js and css for div and check box elements in .aspx page.Will it be applied to the adding image and div elements for the above mentioned code.
– Sravani Chinta
Mar 26 at 13:16
this code contains a div control thus you can add anything to it, but if you want to take actions on checkboxes and other elements I advise to use javascript and send and receive data to server using ajax
– AhmadMM
Mar 26 at 13:18
if you found it useful, don't forget to mark it as an answer ;)
– AhmadMM
Mar 26 at 13:24
add a comment |
if you are going to read from database you should use OdbcCommand and the code as follows
using (OdbcCommand cmd = new OdbcCommand(yourquery, cn))
using (OdbcDataReader reader = cmd.ExecuteReader())
var divHtml = new System.Text.StringBuilder();
while (reader.Read())
System.Web.UI.HtmlControls.HtmlGenericControl div = new
System.Web.UI.HtmlControls.HtmlGenericControl("div");
div.ID = "div";
div.InnerHtml = String.Format("0", reader.GetString(0));
Image img = new Image();
img.ImageUrl = "~/Images/download_image.jfif";
img.AlternateText = "Dynamic Images";
div.Controls.Add(img);
divHtml.append(div);
subdiv.InnerHtml = divHtml.ToString();
if you are going to read from database you should use OdbcCommand and the code as follows
using (OdbcCommand cmd = new OdbcCommand(yourquery, cn))
using (OdbcDataReader reader = cmd.ExecuteReader())
var divHtml = new System.Text.StringBuilder();
while (reader.Read())
System.Web.UI.HtmlControls.HtmlGenericControl div = new
System.Web.UI.HtmlControls.HtmlGenericControl("div");
div.ID = "div";
div.InnerHtml = String.Format("0", reader.GetString(0));
Image img = new Image();
img.ImageUrl = "~/Images/download_image.jfif";
img.AlternateText = "Dynamic Images";
div.Controls.Add(img);
divHtml.append(div);
subdiv.InnerHtml = divHtml.ToString();
answered Mar 26 at 13:07
AhmadMMAhmadMM
2191 silver badge13 bronze badges
2191 silver badge13 bronze badges
I have defined js and css for div and check box elements in .aspx page.Will it be applied to the adding image and div elements for the above mentioned code.
– Sravani Chinta
Mar 26 at 13:16
this code contains a div control thus you can add anything to it, but if you want to take actions on checkboxes and other elements I advise to use javascript and send and receive data to server using ajax
– AhmadMM
Mar 26 at 13:18
if you found it useful, don't forget to mark it as an answer ;)
– AhmadMM
Mar 26 at 13:24
add a comment |
I have defined js and css for div and check box elements in .aspx page.Will it be applied to the adding image and div elements for the above mentioned code.
– Sravani Chinta
Mar 26 at 13:16
this code contains a div control thus you can add anything to it, but if you want to take actions on checkboxes and other elements I advise to use javascript and send and receive data to server using ajax
– AhmadMM
Mar 26 at 13:18
if you found it useful, don't forget to mark it as an answer ;)
– AhmadMM
Mar 26 at 13:24
I have defined js and css for div and check box elements in .aspx page.Will it be applied to the adding image and div elements for the above mentioned code.
– Sravani Chinta
Mar 26 at 13:16
I have defined js and css for div and check box elements in .aspx page.Will it be applied to the adding image and div elements for the above mentioned code.
– Sravani Chinta
Mar 26 at 13:16
this code contains a div control thus you can add anything to it, but if you want to take actions on checkboxes and other elements I advise to use javascript and send and receive data to server using ajax
– AhmadMM
Mar 26 at 13:18
this code contains a div control thus you can add anything to it, but if you want to take actions on checkboxes and other elements I advise to use javascript and send and receive data to server using ajax
– AhmadMM
Mar 26 at 13:18
if you found it useful, don't forget to mark it as an answer ;)
– AhmadMM
Mar 26 at 13:24
if you found it useful, don't forget to mark it as an answer ;)
– AhmadMM
Mar 26 at 13:24
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55357373%2fhow-to-dynamically-add-images-to-ui-from-code-behind-asp-net-with-all-the-styles%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
have a look at repeaters and how to use a prepeater
– Pete
Mar 26 at 12:39
better to use any of these controls like GridView, ListView or Repeater .. other waay around use 'subdiv.controls.add(img)' in side loop.
– Neeraj Kumar Gupta
Mar 26 at 12:49
The image is same for all the data that is coming from the table and should be displayed side by side and also associated with an url which downloads respective file associated with the data
– Sravani Chinta
Mar 26 at 12:57