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?
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)
DropDownList1.DataBind()
End Sub
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).
esims
Member
89 Points
50 Posts
GridView.DataBind() vs. DropDownList.DataBind()
Apr 15, 2012 03:35 PM|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?
basheerkal
Star
10672 Points
2426 Posts
Re: GridView.DataBind() vs. DropDownList.DataBind()
Apr 15, 2012 04:35 PM|LINK
Problem is not clear. Please explain it with your code
(Talk less..Work more)
tarunSaini
Contributor
2948 Points
985 Posts
Re: GridView.DataBind() vs. DropDownList.DataBind()
Apr 15, 2012 05:29 PM|LINK
check your auto post back property of both control.
esims
Member
89 Points
50 Posts
Re: GridView.DataBind() vs. DropDownList.DataBind()
Apr 15, 2012 11:32 PM|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:
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).
basheerkal
Star
10672 Points
2426 Posts
Re: GridView.DataBind() vs. DropDownList.DataBind()
Apr 16, 2012 06:50 AM|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
(Talk less..Work more)