set last item as selected

4 posts, 1 answers
  1. moegal
    moegal avatar
    278 posts
    Member since:
    Jul 2007

    Posted 29 Nov 2012 Link to this post

    I have a data bound combobox. How can I set the selected value to the last item from my database?

    Thanks, Marty
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 29 Nov 2012 Link to this post

    Hi,

    Try the following code to set last item as selected.
    C#:
    protected void Button1_Click(object sender, EventArgs e)
     {
            int count = RadComboBox1.Items.Count;
            for (int i = 0; i < count; i++)
            {
                RadComboBox1.Items[i].Selected = true;
            }
     }

    Thanks,
    Princy.
  3. moegal
    moegal avatar
    278 posts
    Member since:
    Jul 2007

    Posted 30 Nov 2012 Link to this post

    Princy, thanks.  

    This got me thinking, would this work?

    protected void Button1_Click(object sender, EventArgs e)
     {
             RadComboBox1.Items[RadComboBox1.Items.Count -1].Selected = true;
     }

    Marty
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Dec 2012 Link to this post

    Hi Moegal,

    You can select the last RadComboBoxItem by taking the total count of items as follows.

    C#:
    protected void Button1_Click(object sender, EventArgs e)
     {
             RadComboBox1.Items[RadComboBox1.Items.Count -1].Selected = true;
     }

    Regards,
    Princy.
Back to Top