gridview取行索引和主键

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "AddToBus")
        {
            int index = Convert.ToInt32(e.CommandArgument);   //取行的索引
            string petId = this.GridView1.DataKeys[index].Value.ToString(); //取主键
        }
-----------------------

----------------------------------------------------
gridview 的datakeynames 绑定 主键的问题
--
GridView1.DataKeyNames = new string[ ] { "City_ID" };
///2005的DataKeyNames是一个数组。

原文地址:https://www.cnblogs.com/zjw/p/1233579.html