获取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       }

posted @ 2008-09-02 10:53  dodo-yufan  阅读(1349)  评论(0编辑  收藏  举报