Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 October 31st, 2005, 05:25 PM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date Dropdown Format

I have a ddl that is pulling info from a db. I want it to show the date in a mm-dd-yyyy format and it currently shows the time as well. I am trying to get rid of the time. How do I format in the ddl.

I tried
<asp:DropDownList id="ddlStartDate" runat="server" AutoPostBack="true" DataFormatString="{MM/dd/yyyy}"></asp:DropDownList>


but that didn't work.

I appreciate any help!!!
Thanks

 
Old November 1st, 2005, 01:45 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

In the drodownlist's property window, set the DataTextFormatString property = {0:d}

Jim

 
Old November 1st, 2005, 09:38 AM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you I appreciate that. Now I am having another issue. I am trying to get the DISTINCT dates but it has several repeated dates b/c the times are different. How do I select distinct on date only?


string CommandTextDate = "Select DISTINCT DateTime FROM johnrose.smileReportview";

 
Old November 1st, 2005, 10:57 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

string CommandTextDate = "Select DISTINCT(Convert(Char(10), <col name>, 101)) from johnrose.smileReportview

If you use this syntax, then there is no need to set the DataTextFormatStirng property of the dropdown.

Also if DateTime is you column name, I suggest you change it, DateTime is a reserved word. If you do use it, wrap the column name in brackets.. Ex: select [datetime] from ....



 
Old November 1st, 2005, 11:33 AM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

when I tried using your suggestion I'm getting this error. Do you know how I can fix this?


System.Web.HttpException: DataBinder.Eval: 'System.Data.Common.DbDataRecord' does not contain a property with the name Date_Time.

ddlStartDate.DataSource = myCommand3.ExecuteReader(CommandBehavior.CloseConn ection);
ddlStartDate.DataBind();




 
Old November 1st, 2005, 03:34 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Seems like you are trying to select a column named Date_Time that does not exist. What is your table structure and query?

 
Old November 1st, 2005, 03:41 PM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The Table is a results table that holds responses to an online evaluation. The Date_Time field is entered by the database automatically using the GetDate() function to log when the response was entered.

Here is the query:

string CommandTextDate = "Select DISTINCT Date_Time from smileReportview";

 
Old November 1st, 2005, 04:21 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

The DISTINCT won't work, you need to use the code I gave you above. This is to eliminate the time portion. I am not sure why you are getting an error if you say the column exists. Post all of your code you use to grab the data, and hightlight the line where you get the error.

 
Old November 1st, 2005, 04:30 PM
Authorized User
 
Join Date: Oct 2005
Location: , , .
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the code. I am getting the error on DataBind(). I promise the column exists I am looking at it as I type this.

string CommandTextAve = "Select DISTINCT(Convert(Char(10), Date_Time, 101)) from johnrose.smileReportview";

SqlCommand myCommand4 = new SqlCommand(CommandTextAve, myConnection);

ddlAverageList.DataTextField = "AverageRating";
ddlAverageList.DataValueField = "AverageRating";

myConnection.Open();

ddlAverageList.DataSource = myCommand4.ExecuteReader(CommandBehavior.CloseConn ection);
ddlAverageList.DataBind();


 
Old November 2nd, 2005, 02:23 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

It must be in the way you are using the datareader. Could it be the connection is closed before you bind the dropdownlist? I am not familiar with using datareaders. I usually create a dataset, and then bind to it. Maybe try using a dataset for a test. Also run your query in QA and make sure you are getting the results you want.





Similar Threads
Thread Thread Starter Forum Replies Last Post
date format differs, need to force format somehow patricolsson ASP.NET 2.0 Basics 1 December 3rd, 2009 12:53 AM
Convert British format date to American format? fyr PHP How-To 0 December 19th, 2007 03:17 PM
How to give Date format while entering date Subuana Beginning VB 6 4 March 17th, 2006 07:25 AM
date format differs, need to force format somehow patricolsson HTML Code Clinic 2 January 12th, 2006 05:55 AM
Access SQL Statement to Format a Dropdown List jonesl3 Access 3 November 24th, 2004 10:08 AM





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