how to set the value in html select control

  • Thread starter Mohammed Shafiulla Khadri
  • Start date
M

Mohammed Shafiulla Khadri

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
 
J

James [MS-SDK]

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
--------------------
From: "Mohammed Shafiulla Khadri" <[email protected]>
Subject: how to set the value in html select control
Date: Tue, 31 Jan 2006 19:19:47 +0530
Lines: 104
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-RFC2646: Format=Flowed; Original
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: 202.56.254.61
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.csharp:382323
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top