Solved

Is there a way to validate date entered by a user in Gridview without converting to Templatefield?

Posted on 2014-12-28
5
126 Views
Last Modified: 2015-01-28
Hi, I'm using VS2012.
Is there a way to validate user's date input in the gridview (it's the last column).  There 6 columns, the first is the Edit(auto generated) and the last one is date time type with display format to show only short date.  The grid is datagind,    Is there a way to validate when user modify the date/time column, only date is modified, when they click the Update button?  
The problem is if I convert it to Template field then I lose the ability to format the dispaly to only short date, it would display the entire date and time.  It's okay if I can find a regular expression that does the job but i can't find one that would validate mm/dd/yyyy hh:mm:ss AM/PM.

Thank you
0
Comment
Question by:lapucca
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
dejaanbu earned 500 total points
ID: 40521300
The problem is if I convert it to Template field then I lose the ability to format the dispaly to only short date,
You can specify format right in Eval expression:  Text='<%# Eval("yourDateColumn", "{0:d}") %>'
Or else specify DataFormatString="{0:d}"
make sure ApplyFormatInEditMode = True
0
 
LVL 2

Expert Comment

by:M. Atif Nadeem
ID: 40521414
Hi buddy,

For bounding columns, try this code snippet:

var dataTable = new DataTable();
dataTable.Columns.Add("BDate", typeof(DateTime));
dataGridView1.DataSource = dataTable;

Open in new window


Cheers
0
 

Author Comment

by:lapucca
ID: 40527112
I want to validate the data that users enter, not when data is binding.  Thank you,
0
 

Author Comment

by:lapucca
ID: 40566895
I accepted the 1st solution because it actually works.  Please grant expert credit, close this question and re-instate my ability to post more question.  Thank you.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now