Selected value in Dropdown

4 posts, 0 answers
  1. Anders
    Anders avatar
    12 posts
    Member since:
    Feb 2011

    Posted 05 Jan Link to this post

    Hi, I have a RadGrid with a text box called "Cause" where users can input whatever "Cause they wish.

    Now I want to restrict inout by using a Dropdown, 

    <telerik:GridTemplateColumn DataField="Cause" HeaderText="Cause" UniqueName="Cause">
                        <%# Eval("Cause") %>
                                <telerik:RadDropDownList RenderMode="Lightweight" runat="server" ID="RadDropDownList1"  DataTextField="Cause"
                                    DataValueField="Id" SelectedText='<%#Bind("Cause")%>' DataSourceID="sqlDSOutOfStockTest">

    The only thing not working is that when I try to edit an existing record the Dropdown shows the first record in the Dropdown list , not the actual value I chose. What is it that I am not doing right?

    I'm using VB.

  2. Anders
    Anders avatar
    12 posts
    Member since:
    Feb 2011

    Posted 09 Jan in reply to Anders Link to this post

    No one?

  3. Ivan Danchev
    Ivan Danchev avatar
    1303 posts

    Posted 10 Jan Link to this post

    Hello Anders,

    You need to set the DropDownList's SelectedValue property, not the SelectedText one. I attached a sample page which demonstrates this. The Grid and the dropdown controls (ComboBox, DropDownList) are bound to the Northwind sample database. Note how the DropDownList is declared in the Category column:
    <telerik:RadDropDownList runat="server" ID="RadDropDownList1" DataTextField="CategoryName"
                                   DataValueField="CategoryID" DataSourceID="CategoriesDataSource" SelectedValue='<%#Bind("CategoryID") %>'>

    SelectedValue takes its value from the CategoryID field not the CategoryName.

    Ivan Danchev
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  4. Anders
    Anders avatar
    12 posts
    Member since:
    Feb 2011

    Posted 10 Jan in reply to Ivan Danchev Link to this post

    Thank you Ivan. No code behind needed. With your exampe I realized I also had to add an new field "CauseId" to my table and from there edit my SQL query some. Now it works.

    Much appreciated.

Back to Top