【发布时间】:2014-08-04 18:16:42
【问题描述】:
我有一个分配按钮文本的方法,该按钮位于网格视图中的项目模板内。该方法在 Page_PreRender 或 Page_Load 中触发得很好,但是一旦有人通过内置的分页链接更改页面,结果页面就不会将文本分配给按钮。我在 PageIndexChanged 和 PageIndexChanging 事件中都调用了该方法,但我仍然得到空白按钮。是否有一个事件我可以放入它会导致它在 gridview 页面索引更改时运行?
protected void populateActivationText()
{
foreach (GridViewRow row in allItemGrid.Rows)
{
System.Web.UI.WebControls.Button activationButtonAll = row.FindControl("activationButtonAll") as System.Web.UI.WebControls.Button;
System.Web.UI.WebControls.CheckBox activeCheckAll = row.Cells[7].Controls[0] as System.Web.UI.WebControls.CheckBox;
if (activeCheckAll.Checked)
{
activationButtonAll.Text = "Deactivate";
}
else
{
activationButtonAll.Text = "Activate";
}
}
foreach (GridViewRow row in searchGrid.Rows)
{
System.Web.UI.WebControls.Button activationButtonSearch = row.FindControl("activationButtonSearch") as System.Web.UI.WebControls.Button;
System.Web.UI.WebControls.CheckBox activeCheckSearch = row.Cells[7].Controls[0] as System.Web.UI.WebControls.CheckBox;
if (activeCheckSearch.Checked)
{
activationButtonSearch.Text = "Deactivate";
}
else
{
activationButtonSearch.Text = "Activate";
}
}
}
【问题讨论】:
-
你能把
PageIndexChanged和PageIndexChanging的代码贴出来吗? -
protected void allItemGrid_PageIndexChanged(object sender, EventArgs e) { populateActivationText(); }
-
让我们看看您的 Page_PreRender 和 Page_Load 是什么样子的。请注意,Page_PreRender 在 PageIndexChanged 和 PageIndexChanging 之后触发。让我们看看您的 Page_PreRender 代码
-
EVENT (arguments){populateActivatonText();} --- 我通过在 gridview 的 DataBound 事件中调用 populateActivationText() 来完成这项工作,我不知道这是否是正确的方法但是它按预期工作。