当前位置: 代码迷 >> ASP.NET >> 请教在gridview中的RowCommand事件中怎么获得该列的索引
  详细解决方案

请教在gridview中的RowCommand事件中怎么获得该列的索引

热度:562   发布时间:2013-02-25 00:00:00.0
请问在gridview中的RowCommand事件中如何获得该列的索引?
请问在gridview中的RowCommand事件中如何获得该列的索引?谢谢!

------解决方案--------------------------------------------------------
模板列里放的控件的 CommandArgument 属性设置下值 ,没设置的话好像取不到

CommandArgument = " <%# GridView1.Rows.Count %> "


protected void GridViewIw1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "chooseModel ")
{
int index = Convert.ToInt32(e.CommandArgument);
string CID = GridViewIw1.DataKeys[index].Value.ToString();

}
}

------解决方案--------------------------------------------------------
我得到的方法比较复杂... 是参考MSDN的

首先在GridView1_RowCreated把e.Row.RowIndex赋给当前行的某个按钮的CommandArgument属性,在GridView1_RowCommand中,再根据e.CommandArgument得到当前行索引
  相关解决方案