Solved

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

Posted on 2014-12-28
5
128 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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