Multi Column Rad Combo

2 posts, 0 answers
  1. Rahul
    Rahul avatar
    14 posts
    Member since:
    Feb 2013

    Posted 11 Jun 2013 Link to this post

    Hello,

    As per the client requirement i will be having 2 combo box on my screen 1 combobox will be single column and other will be multicolumn. first Combo box will get populated on page load and second will get populated as per the value selected in First combo box. please let me know how can i do this, i want to populate both the combobox on server side.

    i have done one example but when i am trying to get the selected value from first combo i am getting blank values. please let me know that how can i get the selected value of single column rad combo and multicolumn rad combo.

    bellow  is my code.
    ASPX page
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
    <head runat="server">
        <title></title>
        <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <%--Needed for JavaScript IntelliSense in VS2010--%>
                <%--For VS2008 replace RadScriptManager with ScriptManager--%>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>
        <script type="text/javascript">
            //Put your JavaScript code here.
        </script>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        </telerik:RadAjaxManager>
        <div>
        <table>
        <tr>
        <td>
        <telerik:RadComboBox ID="RADClasification"  EnableLoadOnDemand="True" 
                Runat="server" onitemsrequested="RADClasification_ItemsRequested" 
                onselectedindexchanged="RADClasification_SelectedIndexChanged" 
                onitemdatabound="RADClasification_ItemDataBound">
            </telerik:RadComboBox>
        </td>
        </tr>
        <tr>
            <td>
             <telerik:RadComboBox ID="RadTemplateGroup" Runat="server"  
                    EnableLoadOnDemand="True" onitemsrequested="RadTemplateGroup_ItemsRequested">
                <HeaderTemplate
                        <ul
                             <li>Template Group name</li
                             <li>Effective Date</li>
                        </ul
                   </HeaderTemplate
                   <ItemTemplate
                        <ul
                             <li
                                  <%# DataBinder.Eval(Container.DataItem, "Template_GroupName")%></li
                             <li
                                  <%# DataBinder.Eval(Container.DataItem, "EffectiveDate")%></li
                               
                        </ul
                   </ItemTemplate
                   <FooterTemplate
                        A total of 
                        <asp:literal runat="server" id="RadComboItemsCount" /> 
                        items 
                   </FooterTemplate
      
            </telerik:RadComboBox>
            </td>
        </tr>
      
        </table>
             
      
             
      
        </div>
        </form>
    </body>
    </html>
    ASPX.CS
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
      
    using System.Data;
    using System.Configuration;
    using System.Web.Security;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Telerik.Web.UI;
      
    public partial class Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
      
        }
        protected void RADClasification_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            RADClasification.DataSource = CreateDatatable();
            RADClasification.DataValueField = "Cat_ID";
            RADClasification.DataTextField = "Description";
            RADClasification.DataBind();
      
        }
        private DataTable CreateDatatable()
        {
      
            DataTable dt = new DataTable();
            dt.Columns.Add("Cat_ID", typeof(int));
            dt.Columns.Add("Description", typeof(string));
      
            for (int i = 1; i <= 10; i++)
            {
                dt.Rows.Add(i, "Catagory" + i.ToString());
            }
            return dt;
        }
        private DataTable PopulateTemplateGroup()
        {
            DataTable Dt = new DataTable();
            Dt.Columns.Add("Template_Group_ID",typeof(int));
            Dt.Columns.Add("Template_GroupName",typeof(string));
            Dt.Columns.Add("EffectiveDate",typeof(string));
      
            if (Convert.ToInt32(RADClasification.SelectedValue) > 4)
            {
                Dt.Rows.Add(1, "TG1", "10-May-2013");
                Dt.Rows.Add(2, "TG2", "10-May-2013");
                Dt.Rows.Add(3, "TG3", "10-May-2013");
      
            }
            else
            {
                Dt.Rows.Add(4, "TG4", "20-May-2013");
                Dt.Rows.Add(5, "TG5", "20-May-2013");
                Dt.Rows.Add(6, "TG6", "20-May-2013");
            }
            return Dt;
        }
        protected void RADClasification_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
             
        }
        protected void RadTemplateGroup_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {
            RadTemplateGroup.DataSource = PopulateTemplateGroup();
            
            RadTemplateGroup.DataBind();
      
        }
        protected void RADClasification_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
        {
            e.Item.Text = ((DataRowView)e.Item.DataItem)["Description"].ToString();
            e.Item.Value = ((DataRowView)e.Item.DataItem)["Cat_ID"].ToString();   
      
        }
    }

  2. Plamen
    Admin
    Plamen avatar
    2959 posts

    Posted 14 Jun 2013 Link to this post

    Hi Rahul,

    This is an expected behavior because  onitemsrequested event is making a callback and you can not get the state of the other controls in from it.

    One possible workaround it so set AutoPostBack="true" to the first RadComboBox that will let you get the selected value.
     

    Regards,
    Plamen
    Telerik
    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 the blog feed now.
Back to Top