开发者

ASP.NET Gridview RowUpdating event not firing

开发者 https://www.devze.com 2023-01-31 06:01 出处:网络
HTML Page: <asp:UpdatePanel ID=\"UpdatePanel1\" runat=\"server\" UpdateMode=\"Conditional\" ChildrenAsTriggers=\"true\">

HTML Page:

<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>
 开发者_JAVA技巧                       </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 Code:

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

Hi All,

In above written code only EDIT event is being fired & that is only once after that UPDATE,CANCEL no event is being fired. What am i doing wrong?All I want to do is change the GridRow Color on the basis of the value entered in QTY field.


I figured out the problem. The event was not firing because of the same IDs that i had given to the Label in each row. Hope this helpful to someone.


Not sure about your use of IsPostBackEventControlRegistered - I havent seen it used before but it seems that probably you are wiping out your update event by DataBind() every time in Page_Load().

Page_Load is fired every time the page loads which is then changing what the page is doing by resetting the grid.

Try wrapping the control in:

if(!IsPostBack)
{
  // bind
}

so that it only does this on the first page load.

0

精彩评论

暂无评论...
验证码 换一张
取 消