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

set last item as selected

3 Answers 168 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
moegal
Top achievements
Rank 1
moegal asked on 29 Nov 2012, 06:06 PM
I have a data bound combobox. How can I set the selected value to the last item from my database?

Thanks, Marty

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 30 Nov 2012, 04:38 AM
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.
0
moegal
Top achievements
Rank 1
answered on 30 Nov 2012, 12:15 PM
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
0
Princy
Top achievements
Rank 2
answered on 03 Dec 2012, 04:17 AM
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.
Tags
ComboBox
Asked by
moegal
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
moegal
Top achievements
Rank 1
Share this question
or