Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在多个页面中禁用Gridview中的按钮_C#_Asp.net_Gridview - Fatal编程技术网

C# 在多个页面中禁用Gridview中的按钮

C# 在多个页面中禁用Gridview中的按钮,c#,asp.net,gridview,C#,Asp.net,Gridview,我在一个名为“类型”的列中有按钮。当用户单击按钮时,应禁用该按钮。这在第一页很好,但在第二、第三、第四页就不行了 我的页面中有10行,e.CommandArgument获取行号 我相信按钮在gridview中的填充范围是0到9,e.CommandArgument是1-10。这就是为什么我有(e.CommandArgument)-1,它可以在第一页找到 在第二页中,下一个按钮也是0-9,但我的e.CommandArgument是11-20。有什么想法吗 protected void GridVie

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

我的页面中有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;

}
试试下面的方法

protected void GridViewType_RowCommand(object sender, GridViewCommandEventArgs e)
{
  GridViewRow row = (GridViewRow)(e.CommandSource);
  Button btnVote = (Button)row.FindControl("btnVote");
  btnVote.Enabled = false;
}
请检查以下内容:


您可以将布尔值设置为会话变量,然后从中读取以确定按钮是否已启用。给出错误:System.InvalidCastException:无法将“System.Web.UI.WebControl.GridView”类型的对象强制转换为“System.Web.UI.WebControl.Button”。在SWOTLine.index.GridViewType_row处,命令(对象发送方,GridViewCommandEventArgs e)给出错误:错误9无法将类型“System.Web.UI.Control”隐式转换为“System.Web.UI.WebControl.Button”。存在显式转换(是否缺少强制转换?@Apollo my bad我忘记将控件强制转换为(按钮)