c# - ASP.NET Gridview RowUpdating 事件未触发

标签 c# asp.net events gridview

HTML 页面:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
            <ContentTemplate>
                <asp:GridView ID="Grd_Threshold" runat="server" CellPadding="4" ForeColor="#333333"
                    GridLines="Both" AutoGenerateColumns="false" EmptyDataText="No Records." PageSize="8"
                    AllowPaging="true" OnPageIndexChanging="Grd_Threshold_PageIndexChanging" OnRowCommand="Grd_Threshold_RowCommand"
                    DataKeyNames="ID" AutoGenerateEditButton="true" OnRowCancelingEdit="Grd_Threshold_RowCancelingEdit" OnRowEditing="Grd_Threshold_RowEditing"
                    OnRowUpdating="Grd_Threshold_RowUpdating">
                    <Columns>                        
                        <asp:TemplateField HeaderText="No.">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Name" ItemStyle-Width="150px">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("CLNAME") + ", " + Eval("CFNAME") +" " +Eval("CMNAME")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Doctor" ItemStyle-Width="150px">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("DOCTORNAME")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Item Name" ItemStyle-Width="150px">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("INAME")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Item Form" ItemStyle-Width="100px">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("IFORM")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Item Strength" ItemStyle-Width="100px">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("ISTRG")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Order Date" ItemStyle-Width="100px">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("ORDERDATE")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Price" ItemStyle-Width="80px">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("PRICE")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Quantity" ItemStyle-Width="80px">
                            <EditItemTemplate>
                                <asp:TextBox ID="Txt_Qty" runat="server" Width="50px" Text='<%# Eval("QTY")%>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("QTY")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="User" ItemStyle-Width="100px">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("USERID")%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <RowStyle BackColor="#E3EAEB" />
                    <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#7C6F57" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>

CS 代码:

 protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Title = "Dashboard";
                if (!Master.Page.IsPostBackEventControlRegistered)
                {
                    BindGrid();
                }
            }
            catch (Exception ex)
            {
                Common.WriteLog(ex);
            }
        }

        private void BindGrid()
        {
            try
            {
                if (SessionUtility.DashboardRecords == null || SessionUtility.DashboardRecords.Rows.Count == 0)
                {
                    string WebServiceUrl = SessionUtility.WebServiceUrl + "/GetAllOrders/";
                    JsonArrayCollection ReqResponse = Common.GetWebServiceResponse_MultipleValues(WebServiceUrl, "GET");
                    DataTable Patients = Common.ConvertJsonArrayObjectCollectionToDataTable(ReqResponse);

                    SessionUtility.DashboardRecords = Patients;
                }

                if (SessionUtility.UserRight != "1")
                {
                    //Grd_Threshold.Columns[0].Visible = false;
                    Grd_Threshold.AutoGenerateEditButton = false;
                }
                else if (SessionUtility.UserRight == "1")
                {
                    Grd_Threshold.AutoGenerateEditButton = true;
                }
                Grd_Threshold.DataSource = SessionUtility.DashboardRecords;
                Grd_Threshold.DataBind();
                UpdatePanel1.Update();
            }
            catch (Exception ex)
            {
                Common.WriteLog(ex);
            }
        }

大家好,

在上面编写的代码中,仅触发 EDIT 事件,并且在 UPDATE、CANCEL 之后仅触发一次,没有事件被触发。我做错了什么?我想做的就是根据数量字段中输入的值更改 GridRow 颜色。

最佳答案

我发现了问题所在。由于我为每行中的标签提供的 ID 相同,因此该事件未触发。希望这对某人有帮助。

关于c# - ASP.NET Gridview RowUpdating 事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4468990/

相关文章:

c# - Node.js 相当于 ASP.NET MVC 中的 Controller 吗?

c# - 如何检查字符数组中是否存在特定字符

c# - 在 ASP.NET 中实现存储库和工作单元模式

c# - 为另一个 DataGrid 中的 DataGrid 设置不同的 SelectionChanged 事件处理程序

c# - 想要替代 Response.End()

c# - 程序不会停止休眠计算机

c# - Asp.Net MVC 中强类型 View 数据到底是什么

c# - 如何在 asp :checkboxlist 中获取所选项目的计数

javascript - 了解 jQuery .change 事件

java - 有人可以解释一下 EventQueue 对象的用途吗?