取得.Net 3.5 ListView 樣版內的欄位值方式
<asp:ListView ID="ListView1" runat="server" style="font-size: small"
onitemdatabound="ListView1_ItemDataBound">
<ItemTemplate>
<asp:Label ID="label1 e" runat="server"></asp:Label>
</ItemTemplate>
</asp:ListView>
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
//先將e.Item存放至 dataItem內
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
//利用FindControl取得欄位資料
Label label1 = (e.Item.FindControl("label1") as Label);
//將取得listview內label1的資料存至strlabel1
string strlable1 = DataBinder.Eval(dataItem.DataItem, "label1").ToString();
}
參考資料:http://iambigd.blogspot.tw/2010/07/listview-itemdatabound.html
0 意見: