首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-07-08 
GridView获取操作行索引的问题C# code protected void GridView1_RowCommand(Object sender, GridViewComm

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

热点排行