2009-09-28 54 views

回答

38

使用模板列

<asp:GridView ID="GridView1" runat="server" DataKeyNames="id" DataSourceID="SqlDataSource1" 
    OnRowCommand="GridView1_OnRowCommand"> 
    <Columns> 
     <asp:BoundField DataField="name" HeaderText="Name" /> 
     <asp:BoundField DataField="email" HeaderText="Email" /> 
     <asp:TemplateField ShowHeader="False"> 
      <ItemTemplate> 
       <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="SendMail" 
        Text="SendMail" CommandArgument='<%# Eval("id") %>' /> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 
protected void GridView1_OnRowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName != "SendMail") return; 
    int id = Convert.ToInt32(e.CommandArgument); 
    // do something 
} 
+0

它的作品對我來說非常好。 Tks男士。 – 2017-08-15 16:13:23

相關問題