ASP.NET dynamic data listviewbinding
I am having trouble with binding some data to a listview in ASP.NET. I am making a database mangement page where I can select a table from a database in a combobox. When you select 开发者_开发技巧the table, a listview appears with all the data of that table. Now I want to use databinding and i don't really know how to handle this.
<asp:ListView ID="lvData" runat="server">
<LayoutTemplate>
<table class="tableresults">
<thead>
<tr class="odd">
<th>
<%# Eval('COLUMNTITLE') %>
</th>
</tr>
</thead>
<tbody>
<asp:PlaceHolder ID="ItemPlaceHolder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<th scope="row">
<%# Eval('PROPERTY') %>
</th>
</tr>
</ItemTemplate>
</asp:ListView>
So basically I need some kind of loop in the layouttemplate and itemtemplate that loops over the 'columntitles' and 'values' of the data I get from the database. Can I achieve this with databinding?
So I just use code like this:
lvData.DataSource = getData();
lvData.DataBind();
thx
try use ItemDataBound event will fired after databind for each row of your data, you can manage and edit your content as you want
protected void dlList_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
.....
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
........
}
Regards
精彩评论