• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

Checking date format in DataGrid EditMode TextBox

Hello,

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.

Thanks
0
krypto2000
Asked:
krypto2000
3 Solutions
 
Type25Commented:

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');");
                        
                  }

[vb]

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);
            }





0
 
nauman_ahmedCommented:
look at the following URL for the calendar control:

http://www.eworldui.net/CustomControls/CalendarPopupDemo.aspx

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.
0
 
jyotisinhaCommented:
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
Jyoti.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now