【发布时间】:2015-12-01 07:11:59
【问题描述】:
我想在 DataGrid Asp 中找到 Footertemplate 的控件。但它返回 null 。你能帮帮我吗?
<asp:DataGrid ID="dtgDSSP" runat="server" AutoGenerateColumns="false" OnItemDataBound="dtgDSSP_ItemDataBound"
ShowFooter="true" onselectedindexchanged="dtgDSSP_SelectedIndexChanged">
<Columns>
<asp:TemplateColumn HeaderText="Sản Phẩm">
<ItemTemplate>
<asp:HiddenField ID="HidIDSP" runat="server" />
<asp:DropDownList ID="dropSanPham" runat="server">
</asp:DropDownList>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="dropSPAdd" runat="server">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateColumn>
后面的代码:
protected void dtgDSSP_SelectedIndexChanged(对象发送者,EventArgs e) { DropDownList dropAdd; int footerIndex = dtgDSSP.Controls[0].Controls.Count - 1;
dropAdd = dtgDSSP.Controls[0].Controls[footerIndex].FindControl("dropSPAdd") as DropDownList;
if (dropAdd != null)
{
dropAdd.DataSource = Constant.dictSanPham;
dropAdd.DataValueField = "key";
dropAdd.DataTextField = "value";
dropAdd.DataBind();
}
}
【问题讨论】: