如何在asp.net 的gridview 中添加带有按钮的列? [英] How do I add a column with buttons in to a gridview in asp.net?

查看:47
本文介绍了如何在asp.net 的gridview 中添加带有按钮的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的 gridview 正在填充时,我想添加一个带有一些按钮的额外列,但我似乎无法弄清楚如何,或者什么可能是最好的方法.任何人都可以让我开始吗?

As my gridview is populating I want to add an extra column with some buttons in but I can't seem to figure out how, or what might be the best way. Can anyone get me started?

推荐答案

使用模板列

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

这篇关于如何在asp.net 的gridview 中添加带有按钮的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆