Image source missing while generating HTML elements dynamically in asp.net

boruch

New Member
I have 4 rows in DataTable dt5. I am trying to generate certain html elements dynamically equal to number of times as the rows in dt5.Visual studio code:\[code\]<% for(int i = 0; i < dt5.Rows.Count; i++){%><div id="Div1" class="image_stack" style="margin-left:600px" runat="server" ><img class="stackphotos photo1" src="http://stackoverflow.com/questions/15717268/~/Images/3.jpg" clientidmode="static" runat="server" /><img class="stackphotos photo2" src="http://stackoverflow.com/questions/15717268/~/Images/4.jpg" clientidmode="static" runat="server"/><img class="stackphotos photo3" src="http://stackoverflow.com/questions/15717268/~/Images/5.jpg" clientidmode="static" runat="server"/></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><% } %>\[/code\]I am able to generate the html but the problem is the desired html i.e (view source in mozilla) should be....First Iteration code:\[code\]<div id="ContentPlaceHolder1_Div1" class="image_stack" style="margin-left:600px"><img src="http://stackoverflow.com/questions/15717268/Images/3.jpg" class="stackphotos photo1" /><img src="http://stackoverflow.com/questions/15717268/Images/4.jpg" class="stackphotos photo2" /><img src="http://stackoverflow.com/questions/15717268/Images/5.jpg" class="stackphotos photo3" /></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />\[/code\]but the result i am getting is (browser view source) ...\[code\]<div id="ContentPlaceHolder1_Div1" class="image_stack" style="margin-left:600px"><img class="stackphotos photo1" /><img class="stackphotos photo2" /><img class="stackphotos photo3" /></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><<br /><br />\[/code\]As you can see the 'src' part is missing in the code generated .WHy is src missing?OK, it seems to be working now thanks to Code Rider. now i am trying to get the src from datatable. \[code\] for (int i = 0; i < dt5.Rows.Count; i++) { string a = dt5.Rows[0]["imageurl"].ToString(); string b = dt5.Rows[1]["imageurl"].ToString(); string c = dt5.Rows[2]["imageurl"].ToString(); %> <div id="Div1" class="image_stack" style="margin-left:600px" runat="server" > <img id="Img1" class="stackphotos photo1" src="http://stackoverflow.com/questions/15717268/<%a%>" /> <img id="Img2" class="stackphotos photo2" src="http://stackoverflow.com/questions/15717268/<%b%>" /> <img id="Img3" class="stackphotos photo3" src="http://stackoverflow.com/questions/15717268/<%c%>" /> </div> <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> <% } %>\[/code\]
 
Back
Top