Ayyappan Anbalagan
Ayyappan Anbalagan

Reputation: 11302

how to set focus the dropdown item in the page load event?

Based on my dataset row value , my drop drown will focus the particular list item in page load event.

ddparty.SelectedIndex = ddparty.Items.IndexOf(ddparty.Items.FindByValue(ds.Tables[2].Rows[0][1].ToString()));

i try the above code its not working.

Upvotes: 1

Views: 2848

Answers (2)

Amsakanna
Amsakanna

Reputation: 12944

Don't know if you've set your DataValueField to the datatable's second column. On the other hand if you've set your DataTextField to it, try FindByText instead of FindByValue.

As a side note, try to quickwatch in the debugger, the value of the index you get.

Upvotes: 0

Ahmed Khalaf
Ahmed Khalaf

Reputation: 1220

Setting the property:

mydropdown.SelectedItem

or mydropdown.SelectedValue

Make sure you do this AFTER databinding the dropdown control.

Upvotes: 1

Related Questions