在gridview里的添加一列,里面放置一个按钮,设定其commandname="insertitems"点击此按钮,转到下一页面希望在转到下一页面的同时,取出该按钮所在行的 列名为 ID的值
并保存在Session里面  

解决方案 »

  1.   

        protected void Button1_Click(object sender, EventArgs e) 
        {  
          Button myB = (Button)sender; 
          int myIndex = ((GridViewRow)myB.NamingContainer).RowIndex;//获得行号 
           int myId = Convert.ToInt16(GridView1.DataKeys[myIndex].Value);//获得id 
          Session["sMyId"]=myId;    }
      

  2.   

    在按钮里绑定commandArgument为ID值,rowcommand里取commandargument即得到ID
      

  3.   

    为GridView添加模板列:<asp:TemplateField>
        <ItemTemplate>
            <asp:Button ID="Button1" runat="server" CommandArgument='<%# Eval("ID") %>' OnClick="Button1_Click" Text="跳转" />
        </ItemTemplate>
    </asp:TemplateField>
    后台:protected void Button1_Click(object sender, EventArgs e)
    {
        int id = int.Parse((sender as Button).CommandArgument);
        Session["id"] = id;
        Response.Redirect("下一页面");
    }
      

  4.   

    把ID主键设为GridView的DataKeys,CommandName="Edit" 或其他GridView里有的事件 
    Edit的话,点击生成 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e){}方法 在里面写代码  
    int id = int.Parse(GridView1.DataKeys[e.NewEditIndex].Value.ToString());获取当前行ID的值 存到Session里就OK了