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

Selected value in Dropdown

3 Answers 307 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 05 Jan 2017, 06:54 PM

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">
                    <ItemTemplate>
                    <%# Eval("Cause") %>
                </ItemTemplate>
                <EditItemTemplate>
                            <telerik:RadDropDownList RenderMode="Lightweight" runat="server" ID="RadDropDownList1"  DataTextField="Cause"
                                DataValueField="Id" SelectedText='<%#Bind("Cause")%>' DataSourceID="sqlDSOutOfStockTest">
                            </telerik:RadDropDownList>
                                        </EditItemTemplate>
                       
                 </telerik:GridTemplateColumn>

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.

3 Answers, 1 is accepted

Sort by
0
Anders
Top achievements
Rank 1
answered on 09 Jan 2017, 06:57 PM

No one?

0
Ivan Danchev
Telerik team
answered on 10 Jan 2017, 08:03 AM
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") %>'>
                           </telerik:RadDropDownList>

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

Regards,
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.
0
Anders
Top achievements
Rank 1
answered on 10 Jan 2017, 09:37 AM

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.

Tags
DropDownList
Asked by
Anders
Top achievements
Rank 1
Answers by
Anders
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or