This is a migrated thread and some comments may be shown as answers.

RadMenu Databind large collection

4 Answers 100 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Koen L
Top achievements
Rank 1
Koen L asked on 29 Jun 2012, 10:18 AM
We use the RadMenu control in one of our user controls.
The page which uses this control render very slow.
After profiling the page with a few tools we came to the conclusion the databinding of the RadMenu takes up 90% of the time spent generating the page.

radMenu.DataSource = collection;
radMenu.DataBind();

The collection has about 1500 items in it. How can we optimize the performance, so the control can cope with such a large number of items in its datasource...

Kind regards,

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Jul 2012, 10:15 AM
Hi Koen,

You can increase the performance of RadMenu using Web Service Load on Demand. Here is the sample code I tried based on your scenario which works as expected.

ASPX:
<asp:SqlDataSource ID="SqlDataSource1" runat ="server" ConnectionString ="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT * FROM tree WHERE parent IS NULL " >
</asp:SqlDataSource>
<telerik:RadMenu ID="RadMenu1" runat="server" EnableRoundedCorners="true" DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="id" >
   <WebServiceSettings Path="menu.asmx" Method="GetChildren" />
   <DataBindings>
      <telerik:RadMenuItemBinding Depth="0" ExpandMode="WebService" />
   </DataBindings>
</telerik:RadMenu>

menu.aspx.cs
[WebMethod]
  public RadMenuItemData[] GetChildren(RadMenuItemData item, object context)
  {
       SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM tree WHERE parent = '"+item.Value+"' ", con);
       DataTable dt = new DataTable();
       adapter.Fill(dt);
       List<RadMenuItemData> result = new List<RadMenuItemData>();
       try
       {
          foreach (DataRow row in dt.Rows)
          {
             RadMenuItemData itemData = new RadMenuItemData();
             itemData.Text = row["name"].ToString();
             itemData.Value = row["id"].ToString();
             if (Convert.ToInt32(row["ChildrenCount"]) > 0)
              {
                 itemData.ExpandMode = MenuItemExpandMode.WebService;
              }
             result.Add(itemData);
          }
          return result.ToArray();
        }
    catch
    {
       return null;
    }
  }

Hope this helps.

Thanks,
Princy.
0
Koen L
Top achievements
Rank 1
answered on 04 Jul 2012, 09:11 AM
Thanks. Discovered this method already and works great.

I only have one problem. The radmenu needs to load different items based on the current language. Can I use the context object to deliver the language index to the webservice?

If yes. Where do I need to set this context object?
0
Peter
Telerik team
answered on 05 Jul 2012, 08:46 AM
Hello Koen,

RadMenu does not have the necessary client API to support this scenario. Please, accept our apology for this limitation of the control.

Kind regards,
Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Koen L
Top achievements
Rank 1
answered on 06 Jul 2012, 12:33 PM
So there is no way to add additional information to the RadMenuItemData item or object context in the webservice?
Tags
Menu
Asked by
Koen L
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Koen L
Top achievements
Rank 1
Peter
Telerik team
Share this question
or