我的网格视图是我想要的,当我单击“批准”按钮时,它会插入到我的数据库中
<asp:GridView ID="gridview1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Height="222px" Width="451px">
<Columns>
<asp:ButtonField CommandName="Approve" Text="Approve" ButtonType="Button" />
<asp:ButtonField CommandName="Rejected" ButtonType="Button" Text="Disapprove" />
</Columns>
</asp:GridView>
答案 0 :(得分:0)
将OnRowCommand
事件处理程序添加到您的网格中,如下所示:
<asp:GridView ID="gridview1" runat="server" OnRowCommand="gridview1_RowCommand" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Height="222px" Width="451px">
<Columns>
<asp:ButtonField CommandName="Approve" Text="Approve" ButtonType="Button" />
<asp:ButtonField CommandName="Rejected" ButtonType="Button" Text="Disapprove" />
</Columns>
</asp:GridView>
并在点击时添加以下代码以处理批准命令按钮:
protected void gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.ToLower() == "approve")
{
//Code for inserting items in database goes here.
}
}