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

How get the value selected from a multi-column radComboBox

8 Answers 926 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 26 Apr 2011, 06:59 AM
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

8 Answers, 1 is accepted

Sort by
0
Veronica
Telerik team
answered on 27 Apr 2011, 02:58 PM
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.

0
Satish
Top achievements
Rank 1
answered on 25 Sep 2012, 03:28 PM
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?
0
Kalina
Telerik team
answered on 28 Sep 2012, 01:26 PM
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.
0
Satish
Top achievements
Rank 1
answered on 01 Oct 2012, 01:36 PM
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.
0
Cat Cheshire
Top achievements
Rank 1
answered on 04 Oct 2012, 01:45 PM
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.

0
Satish
Top achievements
Rank 1
answered on 04 Oct 2012, 05:32 PM
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?
0
Cat Cheshire
Top achievements
Rank 1
answered on 10 Oct 2012, 02:30 PM
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;
}
0
Satish
Top achievements
Rank 1
answered on 10 Oct 2012, 05:24 PM
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.
Tags
ComboBox
Asked by
Anders
Top achievements
Rank 1
Answers by
Veronica
Telerik team
Satish
Top achievements
Rank 1
Kalina
Telerik team
Cat Cheshire
Top achievements
Rank 1
Share this question
or