Wednesday, March 28, 2012

Validate data in GridView cell (while editing)

Hi,

Have someone any suggestions how to validate data that user write in GridView cell while editing it,
or even allow him to write only proper characters.

In my gridview user in some cells should only write numbers {1,3,9} in other {1,2,3,4,5}. How to check if he write numbers correctly?

Add the validators to the template field which will control the validatation of the input. For examle,

<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ProductName") %>' Visible = false></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate = "TextBox1" ErrorMessage="RequiredFieldValidator">
</asp:RequiredFieldValidator>
</EditItemTemplate>


For custom validator:http://www.asp.net/QuickStart/aspnet/doc/validation/default.aspx


Thanks

1 comment: