读书人

GridView获取操作行索引的有关问题

发布时间: 2012-07-08 17:43:44 作者: rapoo

GridView获取操作行索引的问题

C# code
 protected void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e) {       int index = Convert.ToInt32(e.CommandArgument);       if (e.CommandName == "del")           string musicno = GridView1.Rows[index].Cells[0].Text;  }


代码如上,页面并没有写CommandArgument这个属性,用这个方法刚开始好使,但是过了一段时间后来就不好使了,没有改过别的地方,请问这是什么原因?

[解决办法]
你的 e.CommandArgument 应该是绑定了分页后的序号?

既然前台页没有绑定任何的CommandArgument

int index = Convert.ToInt32(e.CommandArgument); 这里会出错的。

建议这里打上断点,监视e.CommandArgument的值。

或者在_RowCommand事件中

C# code
  //获取改行  GridViewRow gvr = ((Control)sender).Parent.Parent as GridViewRow;
[解决办法]


给个链接你看看, 获取选中行的

http://wenku.baidu.com/view/1f2fca8c6529647d2728522f.html

读书人网 >asp.net

热点推荐