日期:2014-05-18  浏览次数:20422 次

请问在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得到当前行索引