当我的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 }