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

时间:2013-06-18 17:05:13

标签: c# asp.net gridview

我在一个名为Type的列中有按钮。当用户点击按钮时,应该禁用它。这在第一页中工作正常但在第二页,第三页,第四页上没有。

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

我相信按钮在网格视图中填充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;

}

1 个答案:

答案 0 :(得分:0)

尝试以下

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

相关问题