Monday, March 26, 2012

Validating datagrids that sit inside a control.

I have an ascx page.

On the page I have 2 controls.

Each control contains a datagrid.

Inside the datagrid is a textbox.

Below the two controls I have a link button.

Upon clicking the link button I need to validate the datagrids.

Is this possible and how would I do that?

Hi,

you could also place validator controls into the DataGrid. They can be placed into TemplateColumn just as you can place TextBoxes and other controls.


Ok I nested a range validator into my datagrid. But when I enter values inside the etxt box not error message is displayed. Is there anything else I have to do? Wie up the envets to a column?

Thanks

Here is my HTML code:

<asp:boundcolumn datafield="Credit" readonly="True" headertext="Possible Credit For Day"></asp:boundcolumn>
<asp:templatecolumn headertext="Credits Claimed">
<itemtemplate>
<asp:textbox cssclass="normal" id="txtCreditsClaimed" runat="server"></asp:textbox>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn>
<itemtemplate>
<asp:rangevalidator id="rvCreditsClaimed" controltovalidate="txtCreditsClaimed" maximumvalue='<%# DataBinder.Eval(Container, "DataItem.Credit") %>' errormessage="Credits exceed allowed credits">
</asp:rangevalidator>
</itemtemplate>
</asp:templatecolumn>
</columns>


Hi,

you need additionally to specify the type you want to validate with RangeValidator (Type="Integer" orType="Double" orType="Currency" ) and perhaps the MinimumValue also (0 or something). Check the usage of RangeValidator :http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsrangevalidatorclasstopic.asp

Plus that if you want the field to be required, you also need to have RequiredFieldValidator

No comments:

Post a Comment