1,105,371 Community Members

How to validate controls in each column of a gridview

Member Avatar
shotokanpoloto
Newbie Poster
16 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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>
Member Avatar
JorgeM
IT Addict
6,387 posts since Dec 2011
Reputation Points: 567 [?]
Q&As Helped to Solve: 956 [?]
Skill Endorsements: 172 [?]
Moderator
Featured
Sponsor
 
1
 

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

Member Avatar
shotokanpoloto
Newbie Poster
16 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

ok...and then?

Member Avatar
JorgeM
IT Addict
6,387 posts since Dec 2011
Reputation Points: 567 [?]
Q&As Helped to Solve: 956 [?]
Skill Endorsements: 172 [?]
Moderator
Featured
Sponsor
 
1
 

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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: