GridView文本框未在Web选项卡更改时清除

时间:2012-07-26 14:48:06

标签: c# asp.net .net gridview infragistics

我有一个具有2级网页标签的页面。内容选项卡FIXED和VARIABLE依次具有Web选项卡。此Web选项卡加载了具有gridview的User控件。 我的问题是Gridview中的文本框在从一个子选项卡转到下一个子选项卡时不会被清除。我尝试了所有可能的方法: 1.将网格绑定为null(datasource和DatasoruceId) 网格配置 3.网格列清晰 没有运气!!! ..帮助! 注意:我正在修改javascript文本框中的数据。

<ig:Webtab id="wi" runat="server" width="938px" displaymode="Scrollable" meta:resourcekey="wtabInvestmentTypeResource1">
                                <ClientEvents SelectedIndexChanging="webTab_SelectedIndexChanging" />
                                <AutoPostBackFlags SelectedIndexChanged="On" />
                                <Tabs>
                                    <ig:ContentTabItem runat="server" Text="Variable Investment Type" meta:resourcekey="ContentTabItemResource1">
                                        <Template>
                                            <div class="clear vspacesmall hspacenarrow">
                                            </div>
                                            <ig:WebTab ID="wv" runat="server" Width="908px" DisplayMode="Scrollable" ClientIDMode="Static"
                                                meta:resourcekey="wtabVariableResource1">
                                                <ClientEvents SelectedIndexChanging="webTab_SelectedIndexChanging" />
                                                <AutoPostBackFlags SelectedIndexChanged="On" />     
                                            </ig:WebTab>
                                        </Template>
                                    </ig:ContentTabItem>
                                    <ig:ContentTabItem runat="server" Text="Fixed Investment Type" meta:resourcekey="ContentTabItemResource2">
                                        <Template>
                                            <div class="clear vspacesmall hspacenarrow">
                                            </div>
                                            <ig:WebTab ID="wf" runat="server" Width="908px" DisplayMode="Scrollable" class="tabs"
                                                meta:resourcekey="wtabFixedResource1">
                                                <ClientEvents SelectedIndexChanging="webTab_SelectedIndexChanging" />
                                                <AutoPostBackFlags SelectedIndexChanged="On" />
                                            </ig:WebTab>  

Web选项卡加载具有以下gridview的用户控件:

  <div class="clear vspacesmall gridtablearea scrollPanel-horizontal Contol-Max-Height">
                <asp:UpdatePanel ID="upBuyMultipleGetDiscount" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:GridView ID="gvInvestmentDetails" runat="server" OnRowDataBound="gvInvestmentDetails_RowDataBound"
                            TabIndex="5" AutoGenerateColumns="False" CssClass="gridtable scrollPanel-horizontal" Width="100%" meta:resourcekey="gvInvestmentDetails_DefaultResource1"
                           EnableViewState="true" ViewStateMode="Enabled" ShowFooter="true" OnRowCommand="gvInvestmentDetails_Row_Command">
                            <Columns>
                                <asp:BoundField DataField="InvestmentTypeId" />
                                <asp:BoundField DataField="CustomerCombinationId" />
                                <asp:BoundField DataField="ProductId" />

                                <asp:TemplateField HeaderText="Account"  ItemStyle-Width="100px" meta:resourcekey="Account">
                                    <ItemTemplate>
                                        <asp:Label ID="lblAccountName" runat="server" Text='<%# Eval("CustomerCombinationName") %>'></asp:Label>
                                    </ItemTemplate>                                
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="Products" ItemStyle-Width="200px" meta:resourcekey="Products">
                                    <ItemTemplate>
                                        <asp:Label ID="lblProductName" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
                                    </ItemTemplate>
                                    <FooterTemplate>
                                        <asp:Label ID="lblTotal" CssClass="fRight boldText" ForeColor="#656565" runat="server" Text='TOTAL :' meta:resourcekey="lblTotal"></asp:Label>
                                    </FooterTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="Phase Investment Amount"  meta:resourcekey="PhaseInvestmentAmount" >
                                    <ItemTemplate>
                                        <asp:Repeater ID="rptrPhases" runat="server" ClientIDMode="Static"  OnDataBinding="rptrPhases_OnDataBinding">
                                            <ItemTemplate>
                                                <div style="float: left; padding: 4px;">
                                                <table id="PhaseDetails">
                                                <tr>
                                                     <td>
                                                     <tr>
                                                    <asp:Label ID="lblPhaseID" runat="server" Text='<%# Eval("PhaseID") %>' Visible="False"></asp:Label>                                               
                                                    <asp:Label ID="lblPhaseName" Class="vspacesmall" runat="server" Text='<%# Eval("PhaseName") %>' ></asp:Label><br />
                                                    <asp:TextBox ID="txtPhaseAmount" runat="server" Text='<%# Eval("PhaseAmount", "{0:F2}") %>'  CssClass="tar"
                                                        ClientIDMode="Static" Width="80px" MaxLength="27" onpaste="return false;"  ViewStateMode="Enabled"
                                                        meta:resourcekey="txtPhaseAmount"></asp:TextBox>
                                                        </tr>
                                                        <tr>
                                                   <asp:Label ID="lblUsageAmount" runat="server" Visible="false" Text='<%# Eval("PhaseUpdateAmount", "{0:F2}") %>'></asp:Label> 
                                                    </tr>
                                                   </td>
                                                   </tr>
                                                   </table>
                                                </div>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </ItemTemplate>
                                    <FooterTemplate>
                                        <asp:Repeater ID="rptTotalAmount" runat="server" ClientIDMode="Static">
                                            <ItemTemplate>
                                             <div style="float: left; padding: 4px;">
                                             <table>
                                             <tr>
                                             <td>
                                                    <asp:TextBox ID="txtPhaseTotal" Text='<%# Eval("PhaseAmount", "{0:F2}") %>' Width="80px" CssClass="tar boldText" 
                                                    ForeColor="#656565" runat="server" ViewStateMode="Enabled" ClientIdMode="Static"  autocomplete="off"  ></asp:TextBox>
                                                    </td>
                                                    </tr>
                                                </table>
                                                </div>
                                            </ItemTemplate>

                                        </asp:Repeater>
                                    </FooterTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="Roles" ItemStyle-Width="150px"   meta:resourcekey="Roles">
                                    <ItemTemplate>
                                        <asp:CheckBoxList ID="chckRoleList"  runat="server" DataTextField="RoleName"  
                                            DataValueField="RoleId" EnableViewState="true" ViewStateMode="Enabled"  onclick="checkBoxLstChanged(this.id,'chkSelectAll');SetIsChanged('1');">
                                        </asp:CheckBoxList>
                                        <asp:RadioButtonList ID="rdbRoleList" runat="server" DataTextField="RoleName" 
                                            DataValueField="RoleId" EnableViewState="true" ViewStateMode="Enabled">
                                        </asp:RadioButtonList>
                                    </ItemTemplate>
                                    <FooterTemplate>
                                        <asp:CheckBox ID="chckSelectAll" runat="server" Text="Select All" onclick="setAllCheckBoxes('chckRoleList',this);SetIsChanged('1');" meta:resourcekey="chckSelectAll">
                                        </asp:CheckBox>
                                        <br>
                                        <asp:Button ID="btnRemove" runat="server" CssClass="btnStyle fLeft" Text="Remove" OnClientClick="return ValidateRemoveRoles('gvInvestmentDetails')"
                                             CommandName="RemoveRoles" CommandArgument='<%# Container.DataItemIndex %>'
                                              meta:resourcekey="btnRemove"  />
                                    </FooterTemplate>
                                </asp:TemplateField>

                                <asp:TemplateField HeaderText="InvestmentAmount" meta:resourcekey="InvestmentAmount">
                                    <ItemTemplate>
                                        <asp:TextBox ID="txtInvAmt" Width="80px" runat="server" Text='<%# Eval("InvestmentAmount","{0:F2}") %>'
                                           ClientIdMode="Static"  ViewStateMode="Enabled" CssClass="fRight tar  boldText" ></asp:TextBox >
                                    </ItemTemplate>
                                    <FooterTemplate>
                                        <asp:TextBox ID="txtTotalInvestment" ClientIdMode="Static" Width="80px" ViewStateMode="Enabled"  CssClass="fRight tar boldText "   ForeColor="#656565" runat="server" />
                                    </FooterTemplate>
                                </asp:TemplateField>
                                     <asp:BoundField DataField="RecordStatus"  />
                            </Columns>
                           <%-- <FooterStyle HorizontalAlign="Left" CssClass="boldText" ForeColor="#656565" />--%>
                        </asp:GridView>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>

用于加载USer控件的后端代码:

 private void LoadInvestmentDetails(int investmentTypeId, WebTab currentWebTab, int tabIndex)
        {
            Panel panel = GetPanelToBeLoaded(investmentTypeId);

            if (currentWebTab.Tabs[tabIndex].Controls.Count == 0)
            {

                    currentWebTab.Tabs[tabIndex].Controls.Add(panel);
                    budgetDetailsControl.Initialize(investmentTypeId);
                    budgetDetailsControl.InvestmentDetailsSaved += new ProjectInvestmentDetailsSavedEventHandler(BudgetDetailsControl_BudgetDetailsSaved);
                    PreviouslyLoadedTab = int.Parse(currentWebTab.Tabs[currentWebTab.SelectedIndex].UserControlUrl);


            }
      // other code 
         }



    private Panel GetPanelToBeLoaded(int investmentTypeId)
    {
        System.Web.UI.Control userControl = GetInvestmentDetailsUserControlUrl();
        Panel panel = new Panel();
        panel.Controls.Add(userControl);
        budgetDetailsControl = (IProjectInvestmentDetailsControl)userControl;
        budgetDetailsControl.InvestmentTypeID = investmentTypeId;
        return panel;
    }


        private System.Web.UI.Control GetInvestmentDetailsUserControlUrl()
        {
            return LoadControl(ProjectCommonKeys.URL_PROJECT_BUDGET_DETAILS);
        }

Usercontrol包含IprojectInvestmentDetails接口,并且首先为绑定等调用UC的initalize函数

1 个答案:

答案 0 :(得分:0)

我弄明白了这个问题。绑定到子选项卡的每个用户控件都会被赋予一个唯一的Id ..或者其他即使我们绑定新数据,来自早期实例的数据也将保持不变。

private Panel GetPanelToBeLoaded(int investmentTypeId)
        {
            System.Web.UI.Control userControl = GetInvestmentDetailsUserControlUrl();
            **userControl.ID = investmentTypeId.ToString();**
            Panel panel = new Panel();
            panel.Controls.Add(userControl);
            projectInvestmentDetailsControl = (IProjectInvestmentDetailsControl)userControl;
            projectInvestmentDetailsControl.InvestmentTypeID = investmentTypeId;
            projectInvestmentDetailsControl.UserContext = userContext;
            projectInvestmentDetailsControl.PlanningWizardDataManager = PlanningWizardDataManager;
            projectInvestmentDetailsControl.PlanningServiceWrapper = PlanningServiceWrapper;

            return panel;
        }` 

谢谢你的帮助...