Last post Apr 16, 2012 07:50 AM by basheerkal
Apr 15, 2012 04:35 PM|esims|LINK
When I call databind from code, the SelectedIndex of a GridView control is retained, whereas the SelectedIndex of a DropDownList gets lost. Is this some inconsistancy or logical, or am I doing something wrong with the DropDownList?
Apr 15, 2012 05:35 PM|basheerkal|LINK
Problem is not clear. Please explain it with your code
Apr 15, 2012 06:29 PM|tarunSaini|LINK
check your auto post back property of both control.
Apr 16, 2012 12:32 AM|esims|LINK
Suppose you have a DropDownList, with the second item selected. The items (for example names of persons) are from a database and when you make changes to the records, you need to update the DropDownList:
Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs)
I would expect that the second item of the DropDownList stays selected after DataBind(), but is is not. This behaviour is different from a GridView, where the selected item stays selected. Just wondering why (problem is
not how to select the second item again).
Apr 16, 2012 07:50 AM|basheerkal|LINK
How do you say Selected item stays selected in GridView. What change yous see when a row is selected?
GridView shows all the items at a time, But DDLs show only one item at a time.
In DropdownList If you select a value. after PostBack that value will remain selected,
If you want specify which item should be selected after post back you can specify DropDownList1.SelectedIndex = the Index value you want to select
If you want to show the last item added as selected.
DropDownList1.SelectedIndex = DropDownList1.Items.Count - 1