【发布时间】:2013-04-07 08:58:23
【问题描述】:
我正在尝试为我的自定义 GridView 创建自定义 BoundField(列)。我在FooterRow 中添加了文本框来管理对列的过滤。它显示良好,但从未引发 TextChanged 事件。我想这是因为文本框在每次回发时都会重新创建,而不是持久化。
这是我的代码:
public class Column : BoundField
{
public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
{
base.InitializeCell(cell, cellType, rowState, rowIndex);
if (cellType == DataControlCellType.Footer)
{
TextBox txtFilter = new TextBox();
txtFilter.ID = Guid.NewGuid().ToString();
txtFilter.Text = "";
txtFilter.AutoPostBack = true;
txtFilter.TextChanged += new EventHandler(txtFilter_TextChanged);
cell.Controls.Add(txtFilter);
}
}
protected void txtFilter_TextChanged(object sender, EventArgs e)
{
// Never get here
}
}
我尝试了一个复选框,它起作用了。
【问题讨论】:
-
是winforms还是asp.net?
-
您可以发布自己的答案 - 并将其标记为已接受
-
您不得更改任何控件的 Id 属性,以免其无法正常工作。在编码中不应该改变
标签: c# asp.net events boundfield