I would like to validate columns in an asp:Gridview but am unsure how to do so as all the tutorials I have found show a previous version on Microsoft Visual Studio (I am using 2010).

How do I validate each column of the Gridview?

Thanks

This is the code of my Gridview generated by visual studio.

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
    DataKeyNames="registrationNo" DataSourceID="SqlDataSource3" 
    onselectedindexchanged="GridView2_SelectedIndexChanged">
    <Columns>
        <asp:BoundField DataField="fullName" HeaderText="fullName" 
            SortExpression="fullName" />
        <asp:BoundField DataField="address" HeaderText="address" 
            SortExpression="address" />
        <asp:BoundField DataField="work" HeaderText="work" 
            SortExpression="work" />
        <asp:BoundField DataField="home" HeaderText="home" SortExpression="home" />
        <asp:BoundField DataField="mobile" HeaderText="mobile" 
            SortExpression="mobile" />
        <asp:BoundField DataField="registrationNo" HeaderText="registrationNo" 
            InsertVisible="False" ReadOnly="True" SortExpression="registrationNo" />
        <asp:ButtonField ButtonType="Button" CommandName="Edit" HeaderText="Edit" 
            ShowHeader="True" Text="Edit" />
        <asp:ButtonField ButtonType="Button" CommandName="Update" HeaderText="Update" 
            ShowHeader="True" Text="Update" />
        <asp:ButtonField ButtonType="Button" CommandName="Delete" HeaderText="Delete" 
            ShowHeader="True" Text="Delete" />
    </Columns>
    <HeaderStyle BorderColor="#33CC33" />
    <RowStyle BorderStyle="Double" Font-Names="Monotype Corsiva" />
</asp:GridView>

You would have to convert the typical boundfield into an itemTemplate field.

You need to research the concept of a templateField. In design view, take the gridview and convert one field to a templatefield. Click on the smart tag and click Edit Templates. You will be presented with a dropdown list of the different visible states for that field. There is Item, Edit, Insert Template, etc... You can then change/add additional controls such as a validation control.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.