Checking date format in DataGrid EditMode TextBox

Posted on 2005-03-16
Medium Priority
Last Modified: 2008-01-09

I have a DataGrid that I can edit value.

When the user click "Edit", some textboxes appears where it is possible to edit the text.

The problem is that I have two Date fields and when the user change the date, I want to check if the format is correct before sending the params, otherwise à get an error...

I give 400 points for a function who check the date format.

But in the ideal, I want to make a pop-up calender with the calendar component from the framework and when the user click in the TextBox the calendar appear and the value goes in the textbox. 500 points for this.

Question by:krypto2000
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

Assisted Solution

Type25 earned 150 total points
ID: 13556955

In on your itemdataBound event of the datagrid:

if (e.Item.ItemType == ListItemType.EditItem)
                        HyperLink lnk = (HyperLink)e.Item.Cells[0].Controls[1];
                        TextBox txt = (TextBox)e.Item.Cells[1].Controls[1];

                        lnk.Attributes.Add("onClick", "window.open('datePicker.aspx?updateControl=" + txt.ID + "','','height=200,width=200,left=150,top=100,scrollbars=no,status=yes');");


If e.Item.ItemType = ListItemType.EditItem Then
                        Dim lnk As HyperLink = CType(e.Item.Cells(0).Controls(1), HyperLink)
                        Dim txt As TextBox = CType(e.Item.Cells(1).Controls(1), TextBox)
                        lnk.Attributes.Add("onClick", "window.open('datePicker.aspx?updateControl=" + txt.ID + "','','height=200,width=200,left=150,top=100,scrollbars=no,status=yes');")
End If

create a new webform for you calendar, drag a calendar control to it and on the selectedDatechanged event (or whatever it's called)

            private void date_Changed(object sender, System.EventArgs e)
                  string script;

                  script = "<script language=Javascript>opener.document.forms[0]." + Request["updateControl"] + ".value = '" + cal.SelectedDate.ToShortDateString() + "';window.close();</script>";
                  Page.RegisterStartupScript("update", script);

LVL 25

Accepted Solution

nauman_ahmed earned 900 total points
ID: 13556996
look at the following URL for the calendar control:


For the field validation in edit mode, look at the following URL:

http://msdn.microsoft.com/msdnmag/issues/01/06/Cutting/default.aspx (search for Data Validation)

Best, Nauman.

Assisted Solution

jyotisinha earned 150 total points
ID: 13569172
in edit item template attach a .net compareValidator control beside the editable textbox and set the controlTovalidate="textbox1" and datatype=Date in property page of validator.

on the submit button set the causesValidation=true.

This won't let you submit the page unless there is some correct value entered in grid textfield for date.

hope this helps

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

801 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