Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 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