2016-11-17 16 views
0

在asp.Net webforms上工作时。我意识到并得到很多抱怨。选择下拉列表索引需要花费大量时间来绑定另一个选择索引更改的下拉列表,但确实很简单,但没有运气。Asp.Net C#DropDownList选择索引更改花费大约50到60秒

<div class="col-sm-4"> 
        <div> 
         <asp:Label Text="Category *" ID="LabelCompanyCategory" runat="server"></asp:Label> 
        </div> 
        <div> 
         <telerik:RadComboBox ID="DropDownListCompanyCategory" runat="server" 
          AutoPostBack="true" AppendDataBoundItems="true" 
          Width="100%" CssClass="form-control" CausesValidation="False" 
          DataSourceID="SqlDataSourceCategory" DataTextField="catDescription" DataValueField="CatId" 
          OnSelectedIndexChanged="DropDownListCompanyCategory_SelectedIndexChanged" 
          EmptyMessage="Select Category"> 
         </telerik:RadComboBox> 
         <asp:RequiredFieldValidator runat="server" ErrorMessage="please select a category" Display="Dynamic" 
          ControlToValidate="DropDownListCompanyCategory" ForeColor="Red" ID="rfv2"></asp:RequiredFieldValidator> 
         <asp:SqlDataSource ID="SqlDataSourceCategory" ConnectionString='<%$ ConnectionStrings:MainConnection %>' runat="server" 
          SelectCommand=" select CatId, Catdescription from dbo.category"></asp:SqlDataSource> 
        </div> 
       </div> 
       <div class="col-sm-4" runat="server" id="DivActivity" visible="false"> 
        <div> 
         <asp:Label Text="Activity *" ID="LabelCompanyActivity" runat="server"></asp:Label> 
        </div> 
        <div> 
         <telerik:RadComboBox ID="DropDownListActivity" runat="server" CssClass="form-control" Width="100%" 
          AppendDataBoundItems="false" DataSourceID="SqlDataSourceActivity" EmptyMessage="Select Activity" CausesValidation="False" 
          DataTextField="activity" DataValueField="id"> 
         </telerik:RadComboBox> 
         <asp:RequiredFieldValidator runat="server" ErrorMessage="please select a Activity" 
          ControlToValidate="DropDownListActivity" ForeColor="Red" Display="Dynamic" ID="RequiredFieldValidator1"></asp:RequiredFieldValidator> 
        </div> 
        <asp:SqlDataSource ID="SqlDataSourceActivity" ConnectionString='<%$ ConnectionStrings:MainConnection %>' runat="server" 
         SelectCommand="select activity, id from activity where [email protected]"> 
         <SelectParameters> 
          <asp:ControlParameter ControlID="DropDownListCompanyCategory" PropertyName="SelectedValue" 
           DefaultValue="0" Name="CategoryId" /> 
         </SelectParameters> 
        </asp:SqlDataSource> 
       </div> 

后端代码:

protected void DropDownListCompanyCategory_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    DivActivity.Visible = true; 
    DropDownListActivity.DataBind(); 
} 
+0

您是否检查过'SqlDataSource'中给出的查询执行时间?如果这两个查询在SQL管理工具中的执行时间很短,可能'ViewState'膨胀就成了你的问题。 –

+0

查询不是花时间......其工作绝对没问题,查询中没有复杂性。 –

回答

0

Telerik的组件是惊人的快,但是你必须把它们正确地配置和使用RadAjaxManager。 按照这里的例子: http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multiplecomboboxes/defaultcs.aspx

如果数据集非常大,表现仍然不够好,你必须配置loadOnDemand或恢复到客户端的数据绑定。

+0

Telerik Controls在总体构建中工作正常。即使我在telerik COntrol上创建了完整的网络,他们的工作速度非常快。我的数据集在每个索引中包含1到20行。甚至有些只有1排。但采取相同的时间。有些时间也超过了60秒。应用了许多更正,但没有运气 –

相关问题