How get the value selected from a multi-column radComboBox

9 posts, 0 answers
  1. Anders
    Anders avatar
    11 posts
    Member since:
    Nov 2010

    Posted 26 Apr 2011 Link to this post

    Hi ,I want create a ComboBox with multi-column ,and with dynamic from database.

    I have searched a helpfull article:
    http://andrewwhitten.wordpress.com/2010/05/15/multiple-select-telerik-radcombobox-in-code-behind/

    but I don't know how to get the value from client-side and code behind side

    private string item1
            {
                get
                {
                    RadComboBoxItem item = this.combobox1.SelectedItem; 
                    if (item != null)
                    {
                        Label lbl= item.FindControl("item1") as Label;
                        if (lbl!= null) // is always be null
                            return  lbl.Text;
                    }
                    return "";
                }
            }

    how could I get the selectedItem? 

    or have other better ideas for multi-column radcomboBox? 

    Thanks
  2. Veronica
    Admin
    Veronica avatar
    1213 posts

    Posted 27 Apr 2011 Link to this post

    Hello Anders,

    Please take a look at this demo for multi-column menu and pay attantion to the Button1_Click event handler.

    Feel free to ask me if you have further questions.

    Greetings,
    Veronica Milcheva
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. Satish
    Satish avatar
    18 posts
    Member since:
    May 2009

    Posted 25 Sep 2012 Link to this post

    On button click event we just got only the .Text and .Value. But how can read the other columns values of the grid? Do we need any other event?
  4. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 28 Sep 2012 Link to this post

    Hello Satish,

    Can you explain the scenario that you implement in more details and paste here the RadComboBox definition that you use?

    Regards,
    Kalina
    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.
  5. Satish
    Satish avatar
    18 posts
    Member since:
    May 2009

    Posted 01 Oct 2012 Link to this post

    Hi,
    As Venonica explained above I saw the link
    http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multicolumncombo/defaultcs.aspx
    There in Button1_click event only the SelectedText and SelectedValue of RadComboBox is accessed.
    How can you access the other column details of RadCombobox like City, Title column values in code behind.
  6. Cat Cheshire
    Cat Cheshire avatar
    128 posts
    Member since:
    Jun 2010

    Posted 04 Oct 2012 Link to this post

    There are two combos in that demo - the first one uses LoadOnDemand feature and the second one is populated with some items at code behind.

    In both cases you can start with adding information to RadComboBox item using the attributes - .http://www.telerik.com/help/aspnet-ajax/combobox-custom-attributes.html

    Then in case you populate the combo items from code-behind or via datasource control - you will have access to the SelectedItem at server-side and you will easily get its Attributes.

    If you want to use Load On Demand – the combo items won't be accessible at server-side.
    However you can add a Hidden field to your page and at OnClientSelectedIndexChanged event (http://www.telerik.com/help/aspnet-ajax/combobox-onclientselectedindexchanged.html) set the selecte item attribute as a HiddenField value.
    At Button.Click event you can read the hidden field value along with combo text and selected value.

  7. Satish
    Satish avatar
    18 posts
    Member since:
    May 2009

    Posted 04 Oct 2012 Link to this post

    Hi Cat
    thanks for the reply, I got how to access the multi column combox data from javascript. But when I tried the SelectedIndexChanged event in server side, I am not getting the attribute values. Do you have any code for that?
  8. Cat Cheshire
    Cat Cheshire avatar
    128 posts
    Member since:
    Jun 2010

    Posted 10 Oct 2012 Link to this post

    Here is one sample:

    <telerik:RadComboBox ID="RadComboBox1" runat="server" Width="220px" DropDownWidth="500px" AutoPostBack="true"
         DataTextField="Name" DataValueField="ID" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">    
         <ItemTemplate>
             <%# DataBinder.Eval(Container, "Value")%>
             <%# DataBinder.Eval(Container, "Text")%>          
             attribute value: <%# DataBinder.Eval(Container, "Attributes['Attribute1']")%>
         </ItemTemplate>
     </telerik:RadComboBox>

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
             
            DataTable dataTable = CreateDummyDataSource();
     
            for(int i =0; i<dataTable.Rows.Count; i ++) {
                RadComboBoxItem item = new RadComboBoxItem();
                item.Text = (string)dataTable.Rows[i]["Name"];
                item.Value = dataTable.Rows[i]["ID"].ToString();
                item.Attributes.Add("Attribute1", dataTable.Rows[i]["Attribute1"].ToString());
                 
                RadComboBox1.Items.Add(item);
                item.DataBind();
     
            }
        }
    }
     
    protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        string attribute1Value = this.RadComboBox1.SelectedItem.Attributes["Attribute1"];
    }
     
     
    private static DataTable CreateDummyDataSource()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ID");
        dt.Columns.Add("Name");
        dt.Columns.Add("Attribute1");
         
         
        DataRow row1 = dt.NewRow();
        row1["ID"] = "1";
        row1["Name"] = "Product 1";
        row1["Attribute1"] = "a1";
     
        dt.Rows.Add(row1);
     
        DataRow row2 = dt.NewRow();
        row2["ID"] = "2";
        row2["Name"] = "Product 2";
        row2["Attribute1"] = "a2";
     
        dt.Rows.Add(row2);
     
        DataRow row3 = dt.NewRow();
        row3["ID"] = "3";
        row3["Name"] = "Product 3";
        row3["Attribute1"] = "a3";
     
        dt.Rows.Add(row3);
     
        DataRow row4 = dt.NewRow();
        row4["ID"] = "4";
        row4["Name"] = "Product 4";
        row4["Attribute1"] = "a4";
     
        dt.Rows.Add(row4);
        return dt;
    }
  9. Satish
    Satish avatar
    18 posts
    Member since:
    May 2009

    Posted 10 Oct 2012 Link to this post

    Hi Cat,
    That was simple and I got it with a couple of trials as its new to me.. Thanks for the sample code provided.
Back to Top