获取gridview当前行号

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {
    if (e.CommandName == "Select") {
     int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
        Label1.Text = GridView1.DataKeys[rowIndex].Value.ToString();
      }

    }

1    protected void LinkButton1_Command(object sender, CommandEventArgs e)
2    
{
3           LinkButton lb =
(LinkButton)sender;
4           DataControlFieldCell dcf =
(DataControlFieldCell)lb.Parent;
5           GridViewRow gvr =
(GridViewRow)dcf.Parent;
6           GridView1.SelectedIndex =
gvr.RowIndex;
7       }

你可能感兴趣的:(GridView)