473,668 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting Default

Hi experts.

I have an ASP.Net page with a DropDownList called cboYear. This gets filled
with a c# method as follows.

private void FillYearList() {
SqlConnection cn = new SqlConnection() ;
cn = DatEngine.TimeO ffConn;
SqlCommand sc = new SqlCommand("SEL ECT intYear, Description FROM
dbo.vwYearSelec tor ",cn);
cn.Open();
SqlDataReader dr =sc.ExecuteRead er();

//Set the values to be used from the database for the combo
cboYear.DataSou rce = dr; //attach Datareader
cboYear.DataVal ueField = "intYear"; //specify column that contains the
value to use
cboYear.DataTex tField= "Descriptio n"; //specify column that contains the
value to see
cboYear.DataBin d();
cn.Close(); //Must close this!!!!
dr.Close();
}

The data in vwYearSelector is

intYear Description
2004 2004
2005 2005/2006
2006 2006/2007
2007 2007/2008
All this worked fine in 2004, however now in 2005, the cboYear still
initially shows the 2004. How can I set the cboYear to now display 2005/2006
when the page first loads. 2004 could then be selected if required later.

Thanks
Nov 16 '05 #1
3 1202
Hi jez,

Have you tried setting the SelectedIndex property of the DropDownList to 1
after you have done the databinding?

"jez123456" wrote:
Hi experts.

I have an ASP.Net page with a DropDownList called cboYear. This gets filled
with a c# method as follows.

private void FillYearList() {
SqlConnection cn = new SqlConnection() ;
cn = DatEngine.TimeO ffConn;
SqlCommand sc = new SqlCommand("SEL ECT intYear, Description FROM
dbo.vwYearSelec tor ",cn);
cn.Open();
SqlDataReader dr =sc.ExecuteRead er();

//Set the values to be used from the database for the combo
cboYear.DataSou rce = dr; //attach Datareader
cboYear.DataVal ueField = "intYear"; //specify column that contains the
value to use
cboYear.DataTex tField= "Descriptio n"; //specify column that contains the
value to see
cboYear.DataBin d();
cn.Close(); //Must close this!!!!
dr.Close();
}

The data in vwYearSelector is

intYear Description
2004 2004
2005 2005/2006
2006 2006/2007
2007 2007/2008
All this worked fine in 2004, however now in 2005, the cboYear still
initially shows the 2004. How can I set the cboYear to now display 2005/2006
when the page first loads. 2004 could then be selected if required later.

Thanks

Nov 16 '05 #2
Hi,

After databinding, have this:
cboYear.Items.F indByValue(Date Time.Now.Year.T oString()).Sele cted = true;

This will select current year in the drop-down.

HTH.

"jez123456" <je*******@disc ussions.microso ft.com> wrote in message
news:79******** *************** ***********@mic rosoft.com...
Hi experts.

I have an ASP.Net page with a DropDownList called cboYear. This gets filled
with a c# method as follows.

private void FillYearList() {
SqlConnection cn = new SqlConnection() ;
cn = DatEngine.TimeO ffConn;
SqlCommand sc = new SqlCommand("SEL ECT intYear, Description FROM
dbo.vwYearSelec tor ",cn);
cn.Open();
SqlDataReader dr =sc.ExecuteRead er();

//Set the values to be used from the database for the combo
cboYear.DataSou rce = dr; //attach Datareader
cboYear.DataVal ueField = "intYear"; //specify column that contains the
value to use
cboYear.DataTex tField= "Descriptio n"; //specify column that contains the
value to see
cboYear.DataBin d();
cn.Close(); //Must close this!!!!
dr.Close();
}

The data in vwYearSelector is

intYear Description
2004 2004
2005 2005/2006
2006 2006/2007
2007 2007/2008
All this worked fine in 2004, however now in 2005, the cboYear still
initially shows the 2004. How can I set the cboYear to now display 2005/2006
when the page first loads. 2004 could then be selected if required later.

Thanks

Nov 16 '05 #3
Hi,

IT worked by chance, as it was the first value in the list, use the
SelectedIndex property to select the correct one.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"jez123456" <je*******@disc ussions.microso ft.com> wrote in message
news:79******** *************** ***********@mic rosoft.com...
Hi experts.

I have an ASP.Net page with a DropDownList called cboYear. This gets
filled
with a c# method as follows.

private void FillYearList() {
SqlConnection cn = new SqlConnection() ;
cn = DatEngine.TimeO ffConn;
SqlCommand sc = new SqlCommand("SEL ECT intYear, Description FROM
dbo.vwYearSelec tor ",cn);
cn.Open();
SqlDataReader dr =sc.ExecuteRead er();

//Set the values to be used from the database for the combo
cboYear.DataSou rce = dr; //attach Datareader
cboYear.DataVal ueField = "intYear"; //specify column that contains the
value to use
cboYear.DataTex tField= "Descriptio n"; //specify column that contains the
value to see
cboYear.DataBin d();
cn.Close(); //Must close this!!!!
dr.Close();
}

The data in vwYearSelector is

intYear Description
2004 2004
2005 2005/2006
2006 2006/2007
2007 2007/2008
All this worked fine in 2004, however now in 2005, the cboYear still
initially shows the 2004. How can I set the cboYear to now display
2005/2006
when the page first loads. 2004 could then be selected if required later.

Thanks

Nov 16 '05 #4

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

Similar topics

3
5288
by: Florian | last post by:
I need to set multiple values for some SQL statements, for example SET NUMERIC_ROUNDABORT OFF GO SET ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_YIELDS_NULL,ARITHABORT,QUOTED_IDENTIF IER,ANSI_NULLS ON GO in a .sql file, but would like to reset them to their previous settings
4
4022
by: blu4899 | last post by:
Hi, The Xerces XML parser is reading external DTD references in DOCTYPEs by default, but is not doing anything with them because validation is turned off by default. This is documented in http://xml.apache.org/xerces2-j/features.html#nonvalidating.load-external-dtd This setting causes many XML instances with broken DTD references in the DOCTYPE to fail and adds some performance overhead. Is there anything good that comes from this...
18
2169
by: fleemo17 | last post by:
My organization is developing a set of "standards" for websites built inhouse. The first question that comes to mind is what would be a good standard default size for <p> text? 12 point? Which begs the question, what unit of measurement should we use for specifying font sizes, points or ems? Thanks. -Fleemo
18
18360
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
1
2574
by: CES | last post by:
All, Could someone please point me to a step by step resource on setting up a ..net Web Application on IIS. I'm having a problem setting up IIS to except a new Web Application. I'm deploying the default Asp.net Web Application as is setup by VStudio with no code changed, other then adding "Hello World to the <title> tag. I've been able to narrow down the problem to IIS by compiling the Application and deploying it to my production...
14
3987
by: Roger Withnell | last post by:
How to I find out what size text the browser is set to? Thanks in anticipation.
1
6477
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
7
6181
by: Academic | last post by:
What are the different effects of the following two statements: C1.Cursor = Cursors.WaitCursor C1.Cursor.Current = Cursors.WaitCursor I believe the first replaces the entire C1.Cursor object with a new one while the second only replaces the Current object of C1.Cursor, but I can't
8
16092
by: Andrus | last post by:
..NET 2 Winforms application. How to create new setting and set it default value in userSettings section of app.config file or overwrite existing setting value ? I found code below in this list which modifies Application setting section but how to add new item to userSettings ? Andrus.
7
1732
by: PetterL | last post by:
I have a setting called My.settings.firstrun set to True, set in the setting manager. When i read this in the first form form_Load in a IF sentence it always come out as false. I have tried to change the setting from string to Boolean but no help.
0
8459
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8570
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7391
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.