Help With C# Ienumerable

Posted by Sharpcnet under C# on 12/28/2013 | Points: 10 | Views : 1689 | Status : [Member] | Replies : 2
I have a datatable (dtFav) with 2 columns - path(string) & location(string).
This table can have 0 to 5 rows.

There are 5 divs on the aspx page, each with the foll. structure
<div id="div1" runat="server">
<asp:image id="image1" runat="server"/>
<asp:hyperlink id="fav1" runat="server"></asp:hyperlink>
</div>
Row1 of dtFav will have the content for div1 and so on...eg:
image1.ImageUrl = dr["path"];
fav1.NavigateUrl = dr["location"];

So the code will be something like:

int i=0;
foreach(DataRow dr in dtFav.Rows)
{
i=i+1;
if(i==1)
{
image1.ImageUrl = dr["path"];
fav1.NavigateUrl = dr["location"];
}
else if(i==2)
{
image2.ImageUrl = dr["path"];
fav2.NavigateUrl = dr["location"];
}
else....
}

I know there will be an elegant way to acheive this. Can this be done by using Ienumerable. I have no clue how to move forward. Please advice.




Responses

Posted by: Vuyiswamb on: 12/29/2013 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Dont break your head . This can be easily achieved using a Gridview or a Repeater

http://csharpdotnetfreak.blogspot.com/2009/07/display-images-gridview-from-database.html

Thank you for posting at Dotnetfunda
[Administrator]

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sharpcnet on: 1/5/2014 [Member] Starter | Points: 25

Up
0
Down
@Vuyiswamb. I know how to use both , but they are not an option in this case, as the rows displayed have an irregular format.

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response