Validating in a DataGrid
Validating the data before it is even submitted saves a round-trip. However, for some database logic you may need to have a round-trip (for CustomValidators).
<%# Container.DataItem("Age") %>
<asp:RegularExpressionValidator runat="server" ControlToValidate="txtAge" ErrorMessage="Invalid input for Age"
<asp:textbox runat="server" id="txtAge" value='<%# Container.DataItem("Age") %>' />
This checks to make sure that it is a two digit number.
This article has more been about using TemplateColumns than using web forms, however we have used a series of server controls (RadioButton, checkbox and validation) in a DataGrid to give it more functionality. In the related article - "Using Dropdowns in DataGrids" I will explore using a DropDownList which is more complicated than the usual server controls.