2
我得到了有一個Gridview
內ListView
控制其ItemTemplate
數據綁定到GridView的實例內的ListView的ItemDataBound
<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>
我想在RowDataBound
事件我Gridview
的是火與ID="declaredValue"
價值訪問此標籤當ListView ItemDataBound
火..
列表視圖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=""
但它的價值, 我不知道什麼是訪問其價值的最好時機。
請指教。 謝謝。
更新的問題,我已經從數據'DAL'數據綁定到'DeclaredValue'標籤我只是想簡化我的問題 – Mido 2013-04-29 11:57:10
檢查更新的答案。 – Adil 2013-04-29 12:04:10
It works ..謝謝:) – Mido 2013-04-29 12:09:29