【问题标题】:Disable button in Gridview in multiple pages在多个页面中的 Gridview 中禁用按钮
【发布时间】:2013-06-18 17:05:12
【问题描述】:

我在一个名为“类型”的列中有按钮。当用户单击按钮时,它应该被禁用。这在第一页上运行良好,但在第二、第三、第四页上却不行。

我的页面中有 10 行,e.CommandArgument 获取行号。

我相信在 gridview 中填充的按钮是从 0 到 9 并且 e.CommandArgument 是 1-10。这就是为什么我有 (e.CommandArgument) - 1 并且它可以在第一页找到。

在第二页中,下一个按钮再次是 0-9,但我的 e.CommandArgument 是 11-20。有什么想法吗?

protected void GridViewType_RowCommand(object sender, GridViewCommandEventArgs e)
{  
  Button btnVote = (Button)GridViewType.Rows[Convert.ToInt32(e.CommandArgument) - 1].FindControl("btnVote");
  btnV ote.Enabled = false;

}

【问题讨论】:

  • 您可以将布尔值设置为会话变量,然后从中读取以确定按钮是否启用。

标签: c# asp.net gridview


【解决方案1】:

试试下面的

protected void GridViewType_RowCommand(object sender, GridViewCommandEventArgs e)
{
  GridViewRow row = (GridViewRow)(e.CommandSource);
  Button btnVote = (Button)row.FindControl("btnVote");
  btnVote.Enabled = false;
}

请检查:

want to Find Control in gridview on RowCommand event

【讨论】:

  • 给出错误:System.InvalidCastException:无法将“System.Web.UI.WebControls.GridView”类型的对象转换为“System.Web.UI.WebControls.Button”类型。在 SWOTLine.index.GridViewType_RowCommand(Object sender, GridViewCommandEventArgs e)
  • 给出错误:错误 9 无法将类型“System.Web.UI.Control”隐式转换为“System.Web.UI.WebControls.Button”。存在显式转换(您是否缺少演员表?)
  • @Apollo 我的错,我忘了将控件转换为(按钮)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多