开发者

Gridview RowUpdate behaving weird inside updatepanel

开发者 https://www.devze.com 2022-12-14 06:27 出处:网络
I want to update gridview row. But somehow my gridview rowcount is set to 0 on RowUpdating event. No idea whats going wrong. Please let me know what am doing wrong.

I want to update gridview row. But somehow my gridview rowcount is set to 0 on RowUpdating event. No idea whats going wrong. Please let me know what am doing wrong.

Here is my code:

<asp:UpdatePanel ID="updTrackerItem" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
    <ContentTemplate>
        <table cellspacing="5" id="Table4">
            <tr>
                <td>
                    <asp:Label ID="lblTrackingDate" Text="Enter Request for Task Order Proposals Accepted by Office of Acquisitions Date:"
                        runat="server" AssociatedControlID="txtDate"></asp:Label>
                    <asp:TextBox ID="txtDate" runat="server" MaxLength="11" AutoPostBack="true" OnTextChanged="txtDate_TextChanged"
                        ValidationGroup="valTracker"></asp:TextBox>
                    <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" PopupButtonID="ibtnCalendar2"
                        TargetControlID="txtDate"></ajaxToolkit:CalendarExtender>
                    <asp:ImageButton ID="ibtnCalendar2" ImageUrl="../App_Themes/img/icon-calendar.gif"
                        Width="20px" runat="server" AlternateText="Select Date" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator6" ControlToValidate="txtDate"
                        runat="server" ValidationGroup="valTracker" EnableClientScript="true" ErrorMessage="Please enter Tracking OA Date"></asp:RequiredFieldValidator>
                    <asp:CompareValidator ID="CompareValidator1" runat="server" Type="Date" Operator="DataTypeCheck"
                        ControlToValidate="txtDate" ErrorMessage="Please enter a valid date." ValidationGroup="valTracker"
                        EnableClientScript="true"></asp:CompareValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:GridView ID="gvTrackerItem" runat="server" AutoGenerateColumns="False" CellPadding="5" 
                                            DataKeyNames="TrackerItemID,WorkOrderID,TrackerItemIncrement,WorkOrder_TrackerItemDate"
                                            OnRowEditing="gvTrackerItem_RowEditing1" OnRowUpdating="gvTrackerItem_RowUpdating" 
                                            OnRowCreated="gvTrackerItem_RowCreated" OnRowDataBound="gvTrackerItem_RowDataBound"
                                            OnSelectedIndexChanged="gvTrackerItem_SelectedIndexChanged" OnRowCancelingEdit="gvTrackerItem_RowCancelingEdit"
                                            ShowHeader="False" CssClass="dataTable" ShowFooter="true" FooterStyle-ForeColor="black"
                                            EnableViewState="false">
                        <Columns>
                            <asp:BoundField DataField="TrackerItemDescription" HeaderText="" ShowHeader="False" ReadOnly ="true" 
                                                    FooterText="Total calendar days Calculated:">
                                                    <ItemStyle HorizontalAlign="Left" /></asp:BoundField>
                            <asp:TemplateField ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right">
                        <EditItemTemplate>
                        <asp:TextBox ID="txtEditDate" runat="server" Text='<%# Bind("WorkOrder_TrackerItemDate", "{0:MM-dd-yyyy}") %>'
                                                            MaxLength="11"></asp:TextBox>
                        <ajaxToolkit:CalendarExtender ID="AjaxCal1" runat="server" TargetControlID="txtEditDate"
                                                            PopupButtonID="Image1">
                        </ajaxToolkit:CalendarExtender>
                        <asp:ImageButton ID="Image1" ImageUrl="../App_Themes/img/icon-calendar.gif" Width="20px"
                                                            runat="server" AlternateText="Select Date" />
                        <asp:CompareValidator ID="CompareValidator1" runat="server" Type="Date" Operator="DataTypeCheck"
                                                            ControlToValidate="txtEditDate" ErrorMessage="Please enter a valid date."></asp:CompareValidator>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblDate" runat="server" Text='<%# Bind("WorkOrder_TrackerItemDate") %>'></asp:Label>
                        </ItemTemplate>
                        <FooterTemplate>
                            <asp:Label ID="lblTotal" runat="server" />
                        </FooterTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowEditButton="True" CausesValidation="false" />
                        </Columns>
                        <RowStyle CssClass="ItemStyle" />
                        <HeaderStyle />
                        <AlternatingRowStyle CssClass="AlternatingStyle" />
                        <EmptyDataTemplate>
                             No Schedule Dates Found.
                        </EmptyDataTemplate>
                        </asp:GridView>
                    </td>
                </tr>
            </table>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="gvTrackerItem" EventName="RowUpdating" />
            <asp:AsyncPostBackTrigger ControlID="gvTrackerItem" EventName="RowEditing" />
            <asp:AsyncPostBackTrigger ControlID="gvTrackerItem" EventName="RowCancelingEdit" />
            <asp:AsyncP开发者_如何学运维ostBackTrigger ControlID="gvTrackerItem" EventName="RowDataBound" />
            <asp:AsyncPostBackTrigger ControlID="gvTrackerItem" EventName="RowCreated" />
            <asp:AsyncPostBackTrigger ControlID="txtDate" EventName="TextChanged" />
        </Triggers>
    </asp:UpdatePanel>

    protected void gvTrackerItem_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {               
            //Update the values.
            GridViewRow row = gvTrackerItem.Rows[e.RowIndex];

            TextBox txtDt = (TextBox)gvTrackerItem.Rows[row.RowIndex].FindControl("txtEditDate");
            WorkOrderTrackerItem wti = new WorkOrderTrackerItem();
            wti.WorkOrderID = TaskOrderID;
            wti.TrackerItemID = Convert.ToInt32(gvTrackerItem.DataKeys[row.RowIndex].Values["TrackerItemID"].ToString());
            wti.WorkOrder_TrackerItemDate = Convert.ToDateTime(txtDt.Text);
            WorkOrderManager.SaveRequestTrackerItem(wti);

            //Reset the edit index.
            gvTrackerItem.EditIndex = -1;

            //Bind data to the GridView control.
            LoadTrackerItems(TaskOrderID);
        }


Hai ,

Instead of GridViewRow row = gvTrackerItem.Rows[e.RowIndex];

use this

GridViewRow row =  (GridViewRow)gvTrackerItem.Rows[e.RowIndex]

and see whether you get row index... just give a try

OR

check ur databind method

OR

CausesValidation="false" for update button might do it for you..

0

精彩评论

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