我得到了ListView
控制,它有一个Gridview
内部ItemTemplate
<asp:ListView ID="InboxList" runat="server" OnItemDataBound="InboxList_ItemDataBound" OnItemCreated="InboxList_ItemCreated">
<LayoutTemplate>
<tr runat="server" id="itemPlaceholder"></tr>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label Visible="false" ID="Id" runat="server" Text='<%#Eval("Id") %>' />
</td>
</tr>
<tr>
<td>
<asp:GridView ID="itemsGridView" runat="server" AutoGenerateColumns="False" BorderWidth="0px" ShowFooter="true" ShowHeader="true" HeaderStyle-CssClass="internal" OnRowDataBound="itemsGridView_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Declared Value">
<ItemTemplate>
<asp:Label ID="declaredValue" runat="server" ><%# Eval("DECLAREDVALUE") %></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="anotherValue" runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</ItemTemplate>
我正在尝试使用我的事件中的ID="declaredValue"
值访问此标签,该事件是 Fires when Fire..RowDataBound
Gridview
ListView ItemDataBound
Listview ItemDatabound 事件
protected void InboxList_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem ||e.Item.ItemType == ListViewItemType.InsertItem||e.Item.ItemType == ListViewItemType.EmptyItem)
{
DataTable dt = new DataTable();
DAL.GetDataID(int.Parse(((Label)e.Item.FindControl("Id")).Text), dt);
((GridView)(e.Item.FindControl("itemsGridView"))).DataSource = dt;
((GridView)(e.Item.FindControl("itemsGridView"))).DataBind();
}
}
GridView RowDataBound 事件
protected void itemsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl = (Label)e.Row.FindControl("declaredValue");
if (lbl.Text != "")
{
//Here Text value equals "" always!
string value = lbl.Text;
}
}
if (e.Row.RowType == DataControlRowType.Footer)
{
}
}
我可以访问这个标签,但每次它都是Text=""
但它有价值,我不知道什么是访问它的价值的最佳时间。
请指教。谢谢。