Default Item

7 posts, 0 answers
  1. Christopher Blickley
    Christopher Blickley avatar
    202 posts
    Member since:
    Jan 2004

    Posted 20 Feb 2013 Link to this post

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

    Posted 21 Feb 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 21 Feb 2013 Link to this post

    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.
  5. Christopher Blickley
    Christopher Blickley avatar
    202 posts
    Member since:
    Jan 2004

    Posted 22 Feb 2013 Link to this post

    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
  6. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 25 Feb 2013 Link to this post

    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.
  7. Padma
    Padma avatar
    3 posts
    Member since:
    Aug 2013

    Posted 08 Oct 2013 Link to this post

    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.
  8. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 11 Oct 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017