473,581 Members | 3,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to set the value in html select control

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%">&nb sp;&nbsp;&nbsp; day</td>

<td width="40%">mon th</td>

<td width="34%">yea r</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.globaliz ation namespace and all other
relavant namespaces.

DateTime dt;

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

dt = DateTime.Parse( Convert.ToStrin g(Session["DOB"]), dtCulture,
DateTimeStyles. NoCurrentDateDe fault);

dobday.Value = Convert.ToStrin g(dt.Date);

dobmonth.Value = Convert.ToStrin g(dt.Month);

dobyear.Value = Convert.ToStrin g(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


Jan 31 '06 #1
1 5358
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" <md***********@ hotmail.com>
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: <ey************ **@TK2MSFTNGP10 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
NNTP-Posting-Host: 202.56.254.61
Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
Xref: TK2MSFTNGXA02.p hx.gbl microsoft.publi c.dotnet.langua ges.csharp:3823 23
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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%">&nb sp;&nbsp;&nbsp; day</td>

<td width="40%">mon th</td>

<td width="34%">yea r</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.globaliz ation namespace and all otherrelavant namespaces.

DateTime dt;

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

dt = DateTime.Parse( Convert.ToStrin g(Session["DOB"]), dtCulture,
DateTimeStyles .NoCurrentDateD efault);

dobday.Value = Convert.ToStrin g(dt.Date);

dobmonth.Val ue = Convert.ToStrin g(dt.Month);

dobyear.Valu e = Convert.ToStrin g(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



Jan 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2429
by: TDN | last post by:
Hi, I expect to see "foo" for the 2nd alert. Instead, the value of select is cleared. Am I missing something? Thanks for your help. <html> <head><title>Foo</title> <script language="javascript"> <!-- function foo()
12
2326
by: Mark Kurten | last post by:
i have the code below: for starters the value of txtempid = 1 after i go through this routine (i put a break point on the txtname.value line), the value of txtEmpID is 2 (Just like it is suppose to be) However, when i come into this function again, txtEmpID = 1 again For some reason the txtEmpID.value isn't retaining its actual value of 2...
2
2502
by: Alani | last post by:
Hello All, I'm a new ASP.NET programmer and I want to create a custom control consist of two properties (Number1) and (Number2) and both of them are integers and default value = 0, now I'm using callback technique so I can change those two proprties via ChangeNumber1 and ChangeNumber2 functions. what happens is that when I change the...
7
13431
by: skeddy | last post by:
In a nutshell, I'm trying to dynamically create a select box with ResultSet code in vbscript and then need to be able to access the value of that select box later with a Save button. I've got the select box filling with code similar to below: <SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER> Public Sub BuildComboBox(rs, dispname, val, name,...
3
2116
by: dcassar | last post by:
I am working on a complex server control that dynamically creates an HtmlInputHidden control that stores its value. As far as the postback process is concerned, this hidden input acts as the control itself. So when I render, I generate a proxy HtmlInputHidden like so: protected virtual void Render(HtmlTextWriter writer) { HtmlInputHidden...
4
1693
by: TS | last post by:
In my production exceptions i get an email with all the form elements and their values to debug. the controls that have a blank value are not seen and it makes my debug job harder (was the control's value blank or was it set invisible on server so its not in the html). how do i access all controls whether blank or not? thanks
9
9676
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a master-child link to the first subform. subform2 - Master Field: subTrainingModule.Form!TrainingModuleTopicSK Child Field: TrainingModuleTopicSK
2
2013
by: Gary Dale | last post by:
I have a form with a pull-down list with six options, each of which has a value set. The value is the e-mail account name (without the domain) of a group while the displayed value is the full name of the group that will receive the e-mail. I pass this.form to a function to validate the other data before handing it off to a script to...
2
2147
by: j.t.w | last post by:
This is probably very easy. How do I set an HTML select control's value from the querystring? This is what I have...but, only the select control's value doesn't get set. CustomerSelect.Value = Request.QueryString("cus") StartDate.Text = Request.QueryString("Sdate") This works...
0
7886
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8159
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8183
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6569
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1413
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.