如何在增加带有按钮的列在asp.net中的GridView? [英] How do I add a column with buttons in to a gridview in asp.net?
本文介绍了如何在增加带有按钮的列在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屋!
查看全文