簡體   English   中英

如何在按鈕單擊 asp.net c# 上更新 GridView 行?

[英]How to update GridView row on button click asp.net c#?

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

單擊按鈕時,如何在gridview更新此特定行? 因此,待審核消息應顯示當前時間和日期。

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

這是示例代碼,希望對您有所幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM