页面代码
 <asp:GridView>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False"  
 ReadOnly="true" SortExpression="id" >
<asp:TemplateField>
  <ItemTemplate>  
  <asp:ImageButton ID="ImageButton1" runat="server" OnClick="Button1_onClick" ImageUrl="~/Admin/Image/修改按钮.jpg" Visible="true" />
  </ItemTemplate>   
  </asp:TemplateField>
<asp:GridView/>
后台代码
  protected void Butto1_onClick(object sender, EventArgs e)
  {
  怎么获得id值  }

解决方案 »

  1.   

    id.row.findcontrol("行里控件id").value
      

  2.   

    for (int i = 0; i < this.GridView1.Rows.Count; i++)
                {
                    (this.GridView1.Rows[i].FindControl("ImageButton1") as ImageButton).ImageUrl.ToString();
                }
      

  3.   

      int row = ((GridViewRow)((ImageButton)sender).NamingContainer).RowIndex;
      这个是活的所在行的行索引,接下来的就好办了
      

  4.   

    前台 直接把id绑定到button的CommandArgument中
    <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="true"
     SortExpression="id" />
    <asp:TemplateField>
    <ItemTemplate>
    <asp:Button ID="Button1" runat="server" Text="修改"  CommandName="xiugai" CommandArgument='<%#Eval("id") %>'/>
    </ItemTemplate>
    后台直接这样取就行
    protected void grid1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "xiugai")
            {
                Label1.Text = e.CommandArgument.ToString();
            }
        }