At Page_Load I do something like this to set the default value od a DropDownList:
i = int.Parse(somethin from Session);
//e.g. i = 1000
ddlClient.SelectedValue = i.ToString();
//some code
'BREAK POINT'
When debugging at 'BREAK POINT' the SelectedValue of the DDL is always "0", but when the page finishes loading the selected value is the one provided by int i (looking at the page in a browser).
if you are populating the drop down list at load then the first item you add to it will be index 0 and will be the first selected. if you want to change that after you load the dropdown you will want to do something like dropdownlist.selectedIndex = 4
mixy
Member
222 Points
305 Posts
When is DDL's SelectedValue set ?
Apr 30, 2012 03:42 PM|LINK
Hello!
At Page_Load I do something like this to set the default value od a DropDownList:
When debugging at 'BREAK POINT' the SelectedValue of the DDL is always "0", but when the page finishes loading the selected value is the one provided by int i (looking at the page in a browser).
Why?
Thx
www.sanjskadarila.si
AZMatt
Star
10648 Points
1896 Posts
Re: When is DDL's SelectedValue set ?
Apr 30, 2012 03:55 PM|LINK
You will need to do a DataBind() before you try to set the value. The DDL does not have any items in it yet.
Matt
basheerkal
Star
10672 Points
2426 Posts
Re: When is DDL's SelectedValue set ?
Apr 30, 2012 05:18 PM|LINK
How/when do you populate DropDownList?
(Talk less..Work more)
dotnetdev201...
Member
319 Points
79 Posts
Re: When is DDL's SelectedValue set ?
Apr 30, 2012 05:37 PM|LINK
if you are populating the drop down list at load then the first item you add to it will be index 0 and will be the first selected. if you want to change that after you load the dropdown you will want to do something like dropdownlist.selectedIndex = 4
mixy
Member
222 Points
305 Posts
Re: When is DDL's SelectedValue set ?
May 02, 2012 10:21 AM|LINK
thx, this works.
M
www.sanjskadarila.si