473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.TimeOffConn;
SqlCommand sc = new SqlCommand("SELECT intYear, Description FROM
dbo.vwYearSelector ",cn);
cn.Open();
SqlDataReader dr =sc.ExecuteReader();

//Set the values to be used from the database for the combo
cboYear.DataSource = dr; //attach Datareader
cboYear.DataValueField = "intYear"; //specify column that contains the
value to use
cboYear.DataTextField= "Description"; //specify column that contains the
value to see
cboYear.DataBind();
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 1191
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.TimeOffConn;
SqlCommand sc = new SqlCommand("SELECT intYear, Description FROM
dbo.vwYearSelector ",cn);
cn.Open();
SqlDataReader dr =sc.ExecuteReader();

//Set the values to be used from the database for the combo
cboYear.DataSource = dr; //attach Datareader
cboYear.DataValueField = "intYear"; //specify column that contains the
value to use
cboYear.DataTextField= "Description"; //specify column that contains the
value to see
cboYear.DataBind();
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.FindByValue(DateTime.Now.Year.ToStri ng()).Selected = true;

This will select current year in the drop-down.

HTH.

"jez123456" <je*******@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.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.TimeOffConn;
SqlCommand sc = new SqlCommand("SELECT intYear, Description FROM
dbo.vwYearSelector ",cn);
cn.Open();
SqlDataReader dr =sc.ExecuteReader();

//Set the values to be used from the database for the combo
cboYear.DataSource = dr; //attach Datareader
cboYear.DataValueField = "intYear"; //specify column that contains the
value to use
cboYear.DataTextField= "Description"; //specify column that contains the
value to see
cboYear.DataBind();
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*******@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.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.TimeOffConn;
SqlCommand sc = new SqlCommand("SELECT intYear, Description FROM
dbo.vwYearSelector ",cn);
cn.Open();
SqlDataReader dr =sc.ExecuteReader();

//Set the values to be used from the database for the combo
cboYear.DataSource = dr; //attach Datareader
cboYear.DataValueField = "intYear"; //specify column that contains the
value to use
cboYear.DataTextField= "Description"; //specify column that contains the
value to see
cboYear.DataBind();
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
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...
4
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...
18
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...
18
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...
1
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...
14
by: Roger Withnell | last post by:
How to I find out what size text the browser is set to? Thanks in anticipation.
1
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"...
7
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...
8
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...
7
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.