现在的位置: 首页 > 综合 > 正文

获取gridview当前行号

2012年08月15日 ⁄ 综合 ⁄ 共 560字 ⁄ 字号 评论关闭

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       }

抱歉!评论已关闭.