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

Default Item

6 Answers 442 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Christopher
Top achievements
Rank 1
Christopher asked on 20 Feb 2013, 10:13 PM
Is there a quick an easy way to make sure that first item is selected?  After data-binding, the control doesn't have a selection (and the default message would show if set).  I was looking for a property to make sure the first item is selected instead of no selection.  I can easily set it in code-behind, but thought I might be missing something.

Thanks,
Chris

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Feb 2013, 06:38 AM
Hello Christopher

Use the Selected property of DropDownListItem and set it to True.
<telerik:RadDropDownList ID="RadDropDownList1" runat="server" DefaultMessage="Select">
    <Items>
        <telerik:DropDownListItem Text="001" Selected="true" />
          ....................................
    </Items>
</telerik:RadDropDownList>

Thanks
Princy
0
Bozhidar
Telerik team
answered on 21 Feb 2013, 08:24 AM
Hello,

The solution Princy provided works fine when declaring the items through the markup. When you are binding the control to a DataSource, you can use the OnDataBound event to select the first item, like so:
protected void RadDropDownList1_DataBound(object sender, EventArgs e)
{
    if (RadDropDownList1.Items.Count > 0)
    {
        RadDropDownList1.Items[0].Selected = true;
    }
}

 

Kind regards,
Bozhidar
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
Christopher
Top achievements
Rank 1
answered on 22 Feb 2013, 11:12 PM
Thanks, these work and this is what I am already doing.  I guess I was wondering if there was a way to disable the "empty" item when the list contains data, similar to the ASP.NET DropDownList.

Thanks,
Chris
0
Bozhidar
Telerik team
answered on 25 Feb 2013, 09:10 AM
Hi Christopher,

Will will include a property that enables this functionality by default in the upcoming ServicePack. You can follow the release notes to check how this property will be called.
 

Regards,
Bozhidar
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
Padma
Top achievements
Rank 1
answered on 08 Oct 2013, 07:09 PM
Hi,
I am using version 2013.2.717.40 for Telerik dropdownlist and I have a similar issue. The dropdownlist is being populated from the database.The default message displays only when no selection is made but I would like to reset the dropdownlist after each search.
I am doing this using ClearSelection() and my debugger shows the selection cleared. Now the dropdownlist shows the default message, but if no selection is made, I am able to see the previous selction values in the code. Is this a bug?

Also in the absence of default message, if I select one fo the entries using keyboard, the text is displayed but the selection still remains the one which is  selected by mouse. But when the default message is displayed and I make a selection with keyboard, I get the right selection in code.
Can I do a selection using the keyboard without default message? If yes, please give sample code.
0
Bozhidar
Telerik team
answered on 11 Oct 2013, 05:51 AM
Hi Padma,

Could you please clarify the exact steps to reproduce the issues you are experiencing, so that we can properly recreate them locally? The RadDropDownList doesn't have a ClearSelection method, so I'm not quite sure how you are implementing this logic. Also, where in the code do you see the previous selection values?

I'm also not able to reproduce the second issue you are describing. Could you again give specific steps with which to reproduce it?
 

Regards,
Bozhidar
Telerik
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 the blog feed now.
Tags
DropDownList
Asked by
Christopher
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Bozhidar
Telerik team
Christopher
Top achievements
Rank 1
Padma
Top achievements
Rank 1
Share this question
or