簡體   English   中英

如何在asp.net的gridview中添加帶按鈕的列?

[英]How do I add a column with buttons in to a gridview in asp.net?

當我的gridview填充時,我想添加一個帶有一些按鈕的額外列,但我似乎無法弄清楚如何,或者可能是最好的方式。 誰能讓我開始?

使用模板列

<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
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM