Set SelectedItem if no value is selected

6 posts, 0 answers
  1. Angie
    Angie avatar
    101 posts
    Member since:
    Jan 2008

    Posted 09 Jun 2010 Link to this post

    I would like to know at what stage in the ListView lifecycle to set the Selected item so that it takes on the <SelectedItemTemplate> styling.

    I tried doing it at the Prerender and I tried at ItemDataBound, but neither changed the itemstyle properly.

    Thank you.

    This is what I had in the ItemDataBound:


    if (lvGalleries.SelectedValue == null && item.DisplayIndex==0)  
    item.Selected = true;  



  2. Rosen
    Rosen avatar
    3214 posts

    Posted 11 Jun 2010 Link to this post

    Hello Angie,

    There are several ways to se item as selected. In order to set selected items on initial load, you can use page's load event and modify the SelectedIndexes collection.

    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)

    If you want to set it after postback, you may use RadListView's PreRender event, however a rebind of the control will be required.

    Best wishes,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft R3 2016 release webinar banner
  4. yoomee kwon
    yoomee kwon avatar
    7 posts
    Member since:
    Oct 2009

    Posted 15 Apr 2011 Link to this post

    I set the selected to be true and add into selectedindexes but the background color doesn't change which means selecteditemtemplate is not being picked up.  Any idea?


    protected override void OnPreRender(EventArgs e)



    lvOffer.Items[0].Selected =






  5. Veli
    Veli avatar
    2002 posts

    Posted 21 Apr 2011 Link to this post

    As Rosen stated, if you are using PreRender, you need to rebind RadListView. Using either one of your two statements will suffice.

    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  6. Thorsten
    Thorsten avatar
    1 posts
    Member since:
    May 2011

    Posted 14 Jul 2011 Link to this post

    Hi there,

    I am evaluating the Telerik components at the moment and I am bit confused that it is that much of a problem of just selecting an item when loading a page (a common scenario I think).

    Ok, here is my problem:

    I have a RadListView, bound to an EntityDataSource. 
    What I do in the Page_Load-Event is:

    if (!IsPostBack) {
                listViewBox1.DataBind();             // without this, I had nothing 
    //in listViewBox1 during the Page_Load-event

    listViewBox1.Items[0].Selected = true;

    The items gets selected, when I click on the page an a postback occurs.


    OK, I got it now. After the select I did a listViewBox1.Rebind() - is that the correct way to do this?

  7. Veli
    Veli avatar
    2002 posts

    Posted 14 Jul 2011 Link to this post

    Hi Thorsten,

    If you add the index of the selected item in RadListView.SelectedIndexes before databinding, you should get the selected item display right after rebind when the page loads. Are you getting this?

    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top
DevCraft R3 2016 release webinar banner