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

RadCombo selectedvalue

3 Answers 235 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Eva
Top achievements
Rank 1
Eva asked on 22 Dec 2008, 11:23 PM
Hi,
 
I have a rad combo box code given below.

 <telerik:RadComboBox
                    ID="RadComboBox_Agency" runat="server"
                    Height="190px" Width="200px"
                    MarkFirstMatch="true" EnableLoadOnDemand="true" HighlightTemplatedItems="true"
                    DataTextField="CompanyName" DropDownWidth="375" ItemRequestTimeout="500"
                    OnItemsRequested="RadComboBox_Agency_ItemsRequested"
                    Skin="Vista">
                    <HeaderTemplate>
                        <table style="width: 375px" cellspacing="0" cellpadding="0">
                            <tr>
                                <td style="width: 125px;">
                                    Name
                                </td>
                                <td style="width: 125px;">
                                    Phone
                                </td>
                                <td style="width: 125px;">
                                    Zip
                                </td>
                            </tr>
                        </table>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <table style="width: 375px" class="comboTable" cellspacing="0" cellpadding="0">
                            <tr>
                                <td style="width: 125px;" class="comboItemCell">
                                    <div class="comboItem">
                                        <%# DataBinder.Eval(Container.DataItem, "CompanyName")%>
                                    </div>
                                </td>
                                <td style="width: 125px;" class="comboItemCell">
                                    <div class="comboItem">
                                        <%# DataBinder.Eval(Container.DataItem, "Phone")%>
                                    </div>
                                </td>
                                <td style="width: 125px;" class="comboItemCell">
                                    <div class="comboItem">
                                        <%# DataBinder.Eval(Container.DataItem, "PostalCode")%>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </telerik:RadComboBox>



How do i have to get selected value in code behind.
Like 
RadComboBox_Agency.selectedvalue

Thanks.
Eva

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Dec 2008, 06:25 AM
Hi Eva,

Set the DataValueField for the RadComboBox and access the SelectedValue in its SelectedIndexChanged event. Here is the code which I tried on my end.

ASPX:
    <telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="true" AllowCustomText="true" DataTextField="ProductName"  DataValueField="SupplierID"  DataSourceID="SqlDataSource1" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged" OnItemDataBound="RadComboBox1_ItemDataBound" > 
           <ItemTemplate> 
            <table style="width: 375px" class="comboTable" cellspacing="0" cellpadding="0"
                            <tr> 
                                <td style="width: 125px;" class="comboItemCell"
                                    <div class="comboItem"
                                        <%# DataBinder.Eval(Container.DataItem, "ProductName")%> 
                                    </div> 
                                </td> 
                                <td style="width: 125px;" class="comboItemCell"
                                    <div class="comboItem"
                                        <%# DataBinder.Eval(Container.DataItem, "ProductID")%> 
                                    </div> 
                                </td> 
                                <td style="width: 125px;" class="comboItemCell"
                                    <div class="comboItem"
                                        <%# DataBinder.Eval(Container.DataItem, "SupplierID")%> 
                                    </div> 
                                </td> 
                            </tr> 
                        </table> 
         </ItemTemplate> 
        </telerik:RadComboBox> 

CS:
protected void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
        string strSelectedValue = RadComboBox1.SelectedValue; 
        string strSelectedItem = RadComboBox1.SelectedItem.Text; 
    } 


Shinu.
0
James
Top achievements
Rank 2
answered on 24 Feb 2009, 04:22 PM
I just ran into this issue myself. This is quite a roundabout way of getting the selected value from a dropdown. Why does it not have a SelectedValue property? This could be useful for grabbing the selected value in codebehind, but also for declarative binding. I wish I could use it in my scenario - an Edit Form inside a grid that has dropdowns in it.
Instead I'll have to capture the event, save that value somehow, and then grab it when I want to save the record. Silly!
0
kmccusker
Top achievements
Rank 1
answered on 26 Feb 2009, 11:27 PM
The RadComboBox has a SelectedValue property that you can accesss from the code-behind.

If you aren't adding items programmatically to the RadComboBox you need to set the DataValueField property. When the RadComboBox is bound to a data source, the SelectedValue property will be available in the code-behind.

When you bind the RadComboBox to a data source without specifying the DataValueField, you'll end up with empty string values for all your items.
Tags
ComboBox
Asked by
Eva
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
James
Top achievements
Rank 2
kmccusker
Top achievements
Rank 1
Share this question
or