When is DDL's SelectedValue set ?http://forums.asp.net/t/1798537.aspx/1?When+is+DDL+s+SelectedValue+set+Wed, 02 May 2012 10:21:19 -040017985374958530http://forums.asp.net/p/1798537/4958530.aspx/1?When+is+DDL+s+SelectedValue+set+When is DDL's SelectedValue set ? <p>Hello!</p> <p>At Page_Load I do something like this to set the default value od a DropDownList:</p> <pre class="prettyprint">i = int.Parse(somethin from Session); //e.g. i = 1000 ddlClient.SelectedValue = i.ToString(); //some code 'BREAK POINT'</pre> <p>When debugging at 'BREAK POINT' the SelectedValue of the DDL is always &quot;0&quot;, but when the page finishes loading the selected value is the one provided by int i (looking at the page in a browser).</p> <p>Why?</p> <p></p> <p>Thx<br> <br> </p> <p></p> 2012-04-30T15:42:18-04:004958557http://forums.asp.net/p/1798537/4958557.aspx/1?Re+When+is+DDL+s+SelectedValue+set+Re: When is DDL's SelectedValue set ? <p>You will need to do a DataBind() before you try to set the value.&nbsp; The DDL does not have any items in it yet.</p> <pre class="prettyprint">i = int.Parse(somethin from Session); //e.g. i = 1000 ddlClient.DataBind(); ddlClient.SelectedValue = i.ToString(); //some code</pre> <p><br> Matt</p> 2012-04-30T15:55:05-04:004958657http://forums.asp.net/p/1798537/4958657.aspx/1?Re+When+is+DDL+s+SelectedValue+set+Re: When is DDL's SelectedValue set ? <p>How/when do you populate DropDownList?</p> 2012-04-30T17:18:34-04:004958684http://forums.asp.net/p/1798537/4958684.aspx/1?Re+When+is+DDL+s+SelectedValue+set+Re: When is DDL's SelectedValue set ? <p>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</p> 2012-04-30T17:37:40-04:004961495http://forums.asp.net/p/1798537/4961495.aspx/1?Re+When+is+DDL+s+SelectedValue+set+Re: When is DDL's SelectedValue set ? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>AZMatt</h4> <p></p> <p>You will need to do a DataBind() before you try to set the value.&nbsp; The DDL does not have any items in it yet.</p> <pre class="prettyprint">i = int.Parse(somethin from Session); //e.g. i = 1000 ddlClient.DataBind(); ddlClient.SelectedValue = i.ToString(); //some code</pre> <p><br> Matt</p> <p></p> </blockquote> <p></p> <p>thx, this works.</p> <p>M</p> 2012-05-02T10:21:19-04:00