【发布时间】:2012-02-01 10:01:53
【问题描述】:
在 ASP.NET 中,我们喜欢在绑定的网格服务器控件(Girdview 或 ListView)中使用“子”SqlDataSource。
多年来我一直在使用这种FindControl() 方法:
C# 代码隐藏:
protected void gridviewItems_RowDataBound(object sender, GridViewRowEventArgs e)
{
Label labelItemId = (Label)e.Row.FindControl("labelItemId");
}
或者像这样:
protected void buttonSend_Click(object sender, EventArgs e)
{
Label labelItemId = (Label)((Control)sender).NamingContainer.FindControl("labelItemId");
}
没有错,但我已经厌倦了,也许有办法在 .aspx 标记中做到这一点?
类似:
<asp:DropDownList
ID="dropdownItems"
runat="server"
DataSource=<% this.NamingContainer.FindControl("slqdatasourceItems") %>
DataTextField="ItemName"
DataValueField="ItemId" />
这可能吗?
【问题讨论】:
标签: asp.net listview gridview findcontrol