Psst! Did you know DevelopmentNow is a mobile web site design agency?

Contact us for help mobilizing your site, or to sign up for our beta Mobile Web SDK!
all groups > c# > january 2006 >

c# : how to set the value in html select control


Mohammed Shafiulla Khadri
1/31/2006 7:19:47 PM
hi,

I have the following piece of html code in a page


<table width="90%" border="0" align="left" cellpadding="0" cellspacing="0">

<tr>

<td width="26%">&nbsp;&nbsp;&nbsp;day</td>

<td width="40%">month</td>

<td width="34%">year</td>

</tr>

<tr>

<td align="left">

<select name="dobday" id="dobday" style="width:47" tabindex="9"
runat="server"></select>

</td>

<td align="center">

<select name="dobmonth" id="dobmonth" style="width:54" tabindex="10"
runat="server">

<option value="1">JAN</option>

<option value="2">FEB</option>

<option value="3">MAR</option>

<option value="4">APR</option>

<option value="5">MAY</option>

<option value="6">JUN</option>

<option value="7">JUL</option>

<option value="8">AUG</option>

<option value="9">SEP</option>

<option value="10">OCT</option>

<option value="11">NOV</option>

<option value="12">DEC</option>

</select>

</td>

<td align="left">

<input type="text" name="dobyear" id="dobyear" maxlength="4" value="19"
size="3" tabindex="11" runat="server"/>

</td>

</tr>

</table>



and i am trying to assign the value from the server side . The server side
code is as below which uses the system.globalization namespace and all other
relavant namespaces.

DateTime dt;

CultureInfo dtCulture = new CultureInfo("en-US");

dt = DateTime.Parse(Convert.ToString(Session["DOB"]), dtCulture,
DateTimeStyles.NoCurrentDateDefault);

dobday.Value = Convert.ToString(dt.Date);

dobmonth.Value = Convert.ToString(dt.Month);

dobyear.Value = Convert.ToString(dt.Year);



The dt.Date, dt.Month give the correct information but the value is not
assigned correctly in the html select boxes. Please let me know why the
value is not being set?



Regards,

shafi



jamesj NO[at]SPAM online.microsoft.com
1/31/2006 9:18:58 PM
Hello,

Try using dt.Day instead of dt.Date.

Otherwise, your code works just fine.

--
James Johansen, Longhorn SDK
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--------------------
[quoted text, click to view]
AddThis Social Bookmark Button