Solved

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

Posted on 2014-12-28
5
131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 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