473,387 Members | 1,492 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.

DateTime in dropdown

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:
Apr 13 '06 #1
3 1974
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" <CS*******@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
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:

Apr 13 '06 #2
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" wrote:
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" <CS*******@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
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:


Apr 13 '06 #3
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" <CS*******@discussions.microsoft.com> wrote in message
news:DC**********************************@microsof t.com...
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" wrote:
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" <CS*******@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
> 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:
>
>


Apr 13 '06 #4

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

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
13
by: melih.onvural | last post by:
Group, I'm having a tough time understanding some of the previous posts on this topic so I wanted to write what I've tried and hope that you can help me troubleshoot. I have a dropdown populated...
5
by: Gil | last post by:
Is there a way to tell if a combbox is in dropdown mode. I tried and if statement combobox.dropdown = true but i get an error. dropwndown function doesnt store if its true or false what i am...
3
by: devNorway | last post by:
I have been struggling with a problem for days now, and searched for related problems and solutions but had no luck. I have two dropdown listboxes where the first is populated in page load and...
2
by: Jon Vaughan | last post by:
Hi, I was looking for a control that you enter time values into , I started off with a textbox, but then saw the datetime picker had a custom format for Time , so I entered HH:mm. The conctrol...
0
by: veerleverbr | last post by:
I'm looking for a DateTime control that works a bit like the WebDateChooser of Infragistics. This control has a mask which allows only valid dates to be entered. So no alphabetic characters...
5
by: Jeff User | last post by:
Hi all The date values in my dropdown list appear as mm/dd/yyyy Specifically, the day always contains 2 digits. I need to set the selected index of the dropdown to the date that equals another...
5
by: ArizonaState | last post by:
I have a situation where I need to update a table with a time retrieved from a dropdown list. CODE... cmd.SqlParameters.Add((@StartTime, SqlDataType.DateTime).Value = ...
0
by: =?Utf-8?B?a3BpenpsZQ==?= | last post by:
Hi all. using vs.net 9, C# I've got a trivial dilemma right now with my datetimepicker. It is bound to a datetime field in a database. This field is also set to not allow nulls. The default...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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,...
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.