【问题标题】:How to update GridView row on button click asp.net c#?如何更新按钮单击asp.net c#上的GridView行?
【发布时间】:2015-09-17 09:23:40
【问题描述】:
_____________________________
|                |          |
| Pending Review | (Button) |
|________________|__________|
sample gridview row ^

单击按钮时,如何更新gridview 中的这一特定行?因此,待审核消息应显示当前时间和日期。

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:
    <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
    }
    

    这是示例代码,希望对您有所帮助

    【讨论】:

    • 嗨,感谢您的洞察力,但我仍然不确定如何编写背后的代码。我想要这样的东西protected void ButtonReview_Click(object sender, EventArgs e) { //if else code to check if the button is clicked then the text will be updated and display the current date }
    • 长ID进入数据库并与链接按钮绑定,因此您可以轻松获取数据
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    • 2015-04-01
    • 2013-03-01
    相关资源
    最近更新 更多