Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 22nd, 2007, 11:21 PM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deb1980
Default Dynamic combo option selection

Hi,

I have a couple of combo boxes - one having years and the other having months. I want the application to automatically select the current year option and the current option from the respective combo boxes when the page loads.

I have tried this code but it doesnt work:

<select class="select" name="txtsalmonth">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4" <% if(DateTime.Now.month = 4) then response.write("selected") end if%>>April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">Octobet</option>
<option value="11">November</option>
<option value="12">December</option>
</select>

Could you please help?


---
Best regards,

Debashis
__________________
---
Best regards,

Debashis
http://debashis80.spaces.live.com/
 
Old April 23rd, 2007, 07:32 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You should be putting code like this in the page code-behind.

In page load, set the DDL's (there are no combo boxes in standard HTML) selected item to the current month:

If Not IsPostBack Then 'You should probably do this, otherwise a change by the user will be overwritten.
   txtsalmonth.SelectedIndex = DateTime.Now.month - 1 'You need to substract 1 for the 0 based DDL index.
End If


-Peter
 
Old April 23rd, 2007, 12:41 PM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deb1980
Default

Hi Peter,

I have written the as below:

    <select class="select" name="txtsalmonth">
                   <option value="1">January</option>
                   <option value="2">February</option>
                   <option value="3">March</option>
                   <option value="4">April</option>
                   <option value="5">May</option>
                   <option value="6">June</option>
                   <option value="7">July</option>
                   <option value="8">August</option>
                   <option value="9">September</option>
                   <option value="10">Octobet</option>
                   <option value="11">November</option>
                   <option value="12">December</option>
                   </select>
                   <% If Not IsPostBack Then
                       txtsalmonth.SelectedIndex = DateTime.Now.Month - 1
                       End If
                   %>


I am having error:

txtsalmonth not decalred.

I am bit confused on this.


---
Best regards,

Debashis
 
Old April 23rd, 2007, 01:26 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I didn't catch in your first post that it was raw HTML.

Why are you writing raw HTML in (what I can only assume is) an ASP.NET application? You should using a <asp:dropdownlist ... > server control. Then your codebehind will work against that.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
add drop down / combo box for selection mamuco Classic ASP Components 0 May 30th, 2007 06:34 PM
Combo box select affecting avail option in another ebburks Access 4 June 3rd, 2006 05:33 PM
Combo Box -1 Selection Little Shell VB.NET 2002/2003 Basics 5 June 14th, 2005 06:16 PM
Option buttons, queries and combo boxes... Anubis Access VBA 26 November 20th, 2003 12:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.