I am using a datagrid to display and edit values. Among the datagrid columns, I have 2 columns which are the source of this query. The columns are "ValidFromDate" and "ValidToDate". I need to accept only valud dates in these columns and also have the validation that ValidFromDate is less than or equal to ValidToDate. So, for these 2 columns, I have used TemplateColumns. In the EditItemTemplate, for both the columns, I have used a Text box control and 2 CompareValidator controls. The first CompareValidator for both ValidFromDate and ValidToDate does a DataTypeCheck with the data type beingDate. The second ComparatorValidator for ValidFromDate does a LessThanEqualTo check against the ValidToDate. The second CompareValidator for ValidToDate does a GreaterThanEqualTo check against ValidFromDate.
Now, the problem is that I would like to accept the date indd/mm/yyyy format. However, the CompareValidator validates the dates only in mm/dd/yyyy format. How can I overcome this problem?
Secondly, the DataSource for this datagrid is a DataTable. In the datatable, the columns associated to ValidFromDate and ValidToDate are defined as Date type. When I am populating the datatable, I am only populating the date part into these columns. However, when these columns are being displayed in the datagrid, it shows the time part as well with "00:00:00 AM" as the time.The question is how can I eliminate the display of the time part?
Also, when I select a row for editing, the text boxes for ValidFromDate and ValidToDate should the dates with the time part. Even if I do not modify the values and click Update, it shows error from the CompareValidators as the"Date is not Valid" and "Valid From Date should be <= Valid To Date". If I retype the dates into these field with the same value as was displayed without the time part, the errors disappear.Please suggest how I could overcome this problem.
Thanks in advance for your help.
Regards,
Partha.Dear All,
I have a solution for this situation. However, I am not sure if it is a good one.
I added two functions in the code behind page as follows:
ProtectedSub SetDateTextBox(ByVal senderAsObject,ByVal eAs System.EventArgs)
Dim edAs System.Web.UI.WebControls.TextBox = sender
ed.Text =CType(ed.Text,Date).ToString("d")
EndSub
ProtectedSub SetDateLabel(ByVal senderAsObject,ByVal eAs System.EventArgs)
Dim edAs System.Web.UI.WebControls.Label = sender
ed.Text =CType(ed.Text,Date).ToString("d")
EndSub
In the HTML part, I added the following:
<asp:Label id=lblFeatureValidFrom runat="server" Font-Size="XX-Small" Font-Names="Verdana" Text='<%# DataBinder.Eval(Container, "DataItem.validFrom") %>'OnPreRender="SetDateLabel">
</asp:Label>
<asp:TextBox id=txtFeatureValidFrom runat="server" Font-Size="XX-Small" Font-Names="Verdana" Columns="12" MaxLength="10" Text='<%# DataBinder.Eval(Container, "DataItem.validFrom") %>' Wrap="False"OnPreRender="SetDateTextBox" >
</asp:TextBox>
Regards,
Partha.
No comments:
Post a Comment