如何从gridview中提取值

时间:2013-11-30 11:14:30

标签: asp.net gridview

我的网格视图是我想要的,当我单击“批准”按钮时,它会插入到我的数据库中

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

1 个答案:

答案 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.
        }
    }