如何更新GridView行上的按钮点击asp.net c#

本文关键字:按钮 asp net 何更新 更新 GridView | 更新日期: 2023-09-27 18:13:03

_____________________________
|                |          |
| Pending Review | (Button) |
|________________|__________|
sample gridview row ^

我如何在单击按钮时更新gridview中的此特定行?因此,pending review消息应该显示当前时间和日期。

如何更新GridView行上的按钮点击asp.net c#

<asp:GridView ID="gvProduct"
              CssClass="table table-hover table-responsive"
              runat="server"
              PageSize="15"
              AllowPaging="True"
              AllowSorting="True"
              AutoGenerateColumns="False"
              OnPageIndexChanging="gvProduct_PageIndexChanging"
              BackColor="White"
              BorderColor="#CCCCCC"
              BorderStyle="None"
              BorderWidth="1px"
              CellPadding="3"
              ShowHeaderWhenEmpty="true"
              EmptyDataText="Product Not Available">
    <Columns>
        <asp:BoundField DataField="ProductCode"
                        HeaderText="Product Code" />
        <asp:BoundField DataField="ProductName"
                        HeaderText="Product Name" />
        <asp:BoundField DataField="Description"
                        HeaderText="Description" />
        <%-- <asp:BoundField DataField="Type" HeaderText="Type"  />--%>
            <asp:BoundField DataField="Price"
                            HeaderText="Price" />
            <asp:BoundField DataField="qty"
                            HeaderText="Qty" />
            <asp:BoundField DataField="IsActive"
                            HeaderText="Status" />
            <asp:TemplateField>
                <HeaderTemplate>Action</HeaderTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="lnkEdit"
                                    runat="server"
                                    Font-Underline="false"
                                    CssClass="fa fa-pencil"
                                    OnClick="lnkEdit_Click"
                                    CommandArgument='<%# Eval("ID") %>'></asp:LinkButton> &nbsp;|&nbsp;
                    <asp:LinkButton ID="lnkdelete"
                                    runat="server"
                                    Font-Underline="false"
                                    CssClass="fa fa-times"
                                    OnClick="lnkDelete_Click"
                                    CommandArgument='<%# Eval("ID") %>'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="White"
                 ForeColor="#000066" />
    <HeaderStyle BackColor="#006699"
                 Font-Bold="True"
                 ForeColor="White" />
    <PagerStyle BackColor="White"
                ForeColor="#000066"
                HorizontalAlign="Left" />
    <RowStyle ForeColor="#000066" />
    <SelectedRowStyle BackColor="#669999"
                      Font-Bold="True"
                      ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F1F1F1" />
    <SortedAscendingHeaderStyle BackColor="#007DBB" />
    <SortedDescendingCellStyle BackColor="#CAC9C9" />
    <SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>

首先绑定网格视图

以上代码复制到aspx文件中并使用链接按钮并生成链接按钮点击事件

protected void lnkEdit_Click(object sender, EventArgs e)
{
    LinkButton link = (LinkButton)sender;
    long id = Convert.ToInt32(link.CommandArgument);
    //find id of data  and write update logic
}

这是一个示例代码,希望对你有所帮助

查看下面的教程。http://www.aspsnippets.com/Articles/Insert-Update-Edit-Delete-record-in-GridView-using-SqlDataSource-in-ASPNet.aspx