前台<asp:TemplateField><ItemTemplate>
<asp:LinkButton id="lbtnUp" runat="server" __designer:wfdid="w4" CommandName="UP">↑</asp:LinkButton>&nbsp; 
<asp:LinkButton id="lbtnDown" runat="server" __designer:wfdid="w5" CommandName="DOWN">↓</asp:LinkButton> 
</ItemTemplate>
</asp:TemplateField>后台 protected void gvMain_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "UP" || e.CommandName == "DOWN")
        {
//我想在这里取点击的行的索引,下面的是 错误的,应该怎么写
int index = this.gvMain.SelectedRow.RowIndex;
}

解决方案 »

  1.   

    将这句话加到你注释的那里,这是取出当前行,取索引参照这个试试。GridViewRow ContraceptionMethodGridView = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
      

  2.   

    来结贴了,问题已解决。
    int index =Convert.ToInt32(e.CommandArgument);需要先在DataBound事件里:
     LinkButton btnup = (LinkButton)e.Row.FindControl("lbtnUp");        if (btnup != null)
            {            btnup.CommandArgument = e.Row.RowIndex.ToString();        }