DateTime in dropdown

G

Guest

I'm trying to populate a drop down with dates from a data field in my data
base but I want the format like MM/dd/yyyy instead of 1/1/2006 12:00 PM
How can I my date to show as 1/1/2006?

I'm populating the dropdown via a dataset and doing a:
string time =
Convert.ToDateTime(dataset.tables[0].rows[0]["fieldDate"].toString()).ToShortDateString();
dropdown.datatexfield = time;
dropdown.datavaluefield = time
dropdown.databind();

DataBinder.Eval: 'System.Data.DataRowView' does not contain a property with
the name 12/31/2006

and it highlights this code:
dropdown.databind();

what am I missing?

but i'm getting this error:
 
G

Guest

dropdown.datasource = dataset;
should it be different?
even doing this is returning me the dateTime as 1/1/006 12:00 PM

DataSet startDate= SalesForYear.GetStartingDates();
dropDown.DataSource = asOfDate.Tables[0].DefaultView;
dropDown.DataTextField = String.Format("{0:d}", "fieldDate");
ddMonthEnd.DataValueField = String.Format("{0:d}", "fieldDate");
dropDown.DataBind();


Swanand Mokashi said:
What is the DataSource for the dropdownlist ?

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services


CSharpguy said:
I'm trying to populate a drop down with dates from a data field in my data
base but I want the format like MM/dd/yyyy instead of 1/1/2006 12:00 PM
How can I my date to show as 1/1/2006?

I'm populating the dropdown via a dataset and doing a:
string time =
Convert.ToDateTime(dataset.tables[0].rows[0]["fieldDate"].toString()).ToShortDateString();
dropdown.datatexfield = time;
dropdown.datavaluefield = time
dropdown.databind();

DataBinder.Eval: 'System.Data.DataRowView' does not contain a property
with
the name 12/31/2006

and it highlights this code:
dropdown.databind();

what am I missing?

but i'm getting this error:
 
S

Swanand Mokashi

You can not use the formatting function when specifying teh DataTextField or
DataValueField. What is happening is if the date is 1/1/006 12:00 PM, the
DataTextField is "1/1/2006" -- there is no such field in your dataset. Hence
the error.

You can either format the date when you are getting the data (as in
SalesForYear.GetStartingDates method) or use the DataBinding event of the
dropdownlist.


--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services



CSharpguy said:
dropdown.datasource = dataset;
should it be different?
even doing this is returning me the dateTime as 1/1/006 12:00 PM

DataSet startDate= SalesForYear.GetStartingDates();
dropDown.DataSource = asOfDate.Tables[0].DefaultView;
dropDown.DataTextField = String.Format("{0:d}", "fieldDate");
ddMonthEnd.DataValueField = String.Format("{0:d}", "fieldDate");
dropDown.DataBind();


Swanand Mokashi said:
What is the DataSource for the dropdownlist ?

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services


CSharpguy said:
I'm trying to populate a drop down with dates from a data field in my
data
base but I want the format like MM/dd/yyyy instead of 1/1/2006 12:00 PM
How can I my date to show as 1/1/2006?

I'm populating the dropdown via a dataset and doing a:
string time =
Convert.ToDateTime(dataset.tables[0].rows[0]["fieldDate"].toString()).ToShortDateString();
dropdown.datatexfield = time;
dropdown.datavaluefield = time
dropdown.databind();

DataBinder.Eval: 'System.Data.DataRowView' does not contain a property
with
the name 12/31/2006

and it highlights this code:
dropdown.databind();

what am I missing?

but i'm getting this error:
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top