A few DataGrid questions...

1) After you put the datagrid in "edit mode", how do you add validation to the input fields?<BR><BR>2) How can you format the data before it is bound to a column?<BR>Example:<BR><asp:BoundColumn HeaderText="Completion Date" DataField="CompletionDate"/><BR>How can I format the date to the long date format before it is bound to the column?<BR><BR>In relation both questions, can the value that is inserted into the input field when in edit mode be in a different format then when bound to the column?<BR><BR>Much appreciated!You can set the data format in the boundcolumn tag on your datagrid:<BR><BR><BR><ASP:BoundColumn HeaderText="Date" <BR> DataField="rDate" <BR> DataFormatString="{0:D}" /><BR><BR>Where the "D" parameter specified long data while "d" is a short date format.<BR><BR>You can also format your data when taking it from the source database:<BR><BR>select rDate, Format(ActiveDate,"mm/dd/yyyy") from MyTable <BR><BR>Regarding different formats in the input field versus the bound column (12-23-2002 versus 12/23/2002) either one could be formatted long or short in the boundcolumn tag.<BR><BR>As for validation of data entered in the input fields of a datagrid, I haven't looked into it.<BR><BR>Good luck<BR><BR>Tom T<BR><BR>Thanks, the DataFormatString was exactly what I was looking for. In regards to the two different formats: when the datagrid is put into edit mode, it enters into the textbox field whatever the (formatted) value is that is bound to the column. I want the edit mode format to be different.<BR><BR>BoundColumn = Long Date<BR>Edit Column = Short Date<BR><BR>Regards,<BR>DavidI think I got the validation to work. You need to use a TemplateColumn instead of a databound column:<BR><BR><asp:TemplateColumn HeaderText="Approx Completion Date"><BR><BR><ItemTemplate><BR><asp:Label Text='<%#String.Format("{0:D}",Container.DataItem("ApproxCompletionDate"))%>' runat="server"/><BR></ItemTemplate><BR><BR><EditItemTemplate><BR><asp:TextBox id="lblACD" Text=<%#String.Format("{0:d}", Container.DataItem("ApproxCompletionDate"))%> runat="server"/><BR><asp:RequiredFieldValidator<BR>ControlToValidate="lblACD"<BR>Display="Dynamic"<BR>Font-Names="Arial"<BR>Font-Bold="True"<BR>ErrorMessage="<BR>Please enter the completion date."<BR>runat=server/><BR></EditItemTemplate><BR></asp:TemplateColumn><BR><BR>This also allows me to reformat the value in edit mode.<BR><BR>Regards,<BR>David
 
Back
Top