RadCombo selectedvalue

4 posts, 0 answers
  1. Eva
    Eva avatar
    65 posts
    Member since:
    Oct 2007

    Posted 22 Dec 2008 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Dec 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. James
    James avatar
    13 posts
    Member since:
    Feb 2007

    Posted 24 Feb 2009 Link to this post

    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!
  5. kmccusker
    kmccusker avatar
    11 posts
    Member since:
    Sep 2006

    Posted 26 Feb 2009 Link to this post

    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.
Back to Top