【发布时间】:2010-12-31 07:30:42
【问题描述】:
我有一个自定义的 gridview。我的网格只需在标题中单击 1 次即可对每一列进行排序,而无需用户(程序员)进行任何设置和重载方法,例如排序等。(我成功地做到了这一点并且工作正常) 用户(程序员)可能会在网格中添加每一列。例如模板字段、超链接字段、绑定字段...。 对于排序,我必须访问列的数据字段。 我可以通过此代码访问 boundfield 列。我可以访问数据字段和标题文本以及... 示例:
for (int j = 0; j < this.Columns.Count; j++)
{
BoundField bf;
bf = this.Columns[j] as BoundField;
if (bf != null)
{
string ht = bf.HeaderText;
string df = bf.DataField;
}
}
但我可以访问模板字段中的控件。例如 ColumnBound。 示例:
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
我想访问 "Name" (Bind ("Name") 或 Eval ("Name")) 。 我怎样才能? 有一点:我现在不知道模板字段中控件的 ID(在本例中为“Label1”)是什么。 特别感谢
【问题讨论】:
标签: asp.net gridview itemtemplate templatefield