Hi experts,

I need a validator in my gridview.
When the user update a field in the gridview, I need to check if the email is valid.
How can I do that?

Below is my gridview.
Please help. Thanks!

<asp:GridView ID="gv_retrieve" runat="server" AutoGenerateColumns="False" CellPadding="3"
        ForeColor="Black" GridLines="Vertical" Width="751px" OnRowEditing="gv_retrieve_RowEditing" 
        OnRowUpdating="gv_retrieve_RowUpdating" onRowCancelingEdit = "gv_retrieve_RowCancelingEdit" 
        OnRowDeleting = "gv_retrieve_RowDeleting" OnRowDataBound = "gv_retrieve_RowDataBound"
        BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" Font-Bold="False">
        <FooterStyle BackColor="#CCCCCC" />
        
        <Columns>
            
            <asp:BoundField DataField="Name" HeaderText="Name" />
            <asp:BoundField DataField="Designation" HeaderText="Designation" />
            <asp:BoundField DataField="Email" HeaderText="Email Address" />
            <asp:BoundField DataField="WatcherEmail" HeaderText="Watcher Email" />
            <asp:CommandField ShowEditButton="True" >
                <ItemStyle Width="35px" />
            </asp:CommandField>
            <asp:CommandField ShowDeleteButton="True" />
            <asp:BoundField DataField="apid">
                <ItemStyle CssClass="hiddencol" />
            </asp:BoundField>
        </Columns>
        <EmptyDataTemplate>
            <table width="100%">
                <tr style="font-weight:bold; text-decoration:underline" align="center">
                    <td>
                        Name
                    </td>
                    <td>
                        Designation
                    </td>
                    <td>
                        Email
                    </td>
                    <td>
                        WatcherEmail
                    </td>
                </tr>                                                                                  
            </table>                        
             <br />
        </EmptyDataTemplate>
        <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="#CCCCCC" />
    </asp:GridView>

Recommended Answers

All 5 Replies

I never had an inline grid editing form before (I try to separate editing to a different form) but you should try and dynamically add the validation control in the item data bound event (pay attention to the row type (edit)). You could also just check the entry after the post back and keep the grid in edit mode, displaying an error message on top of the page if you did not like the value entered.

Are you familiar with Ajax control toolkit ?
If not then you can find it in google website and get a download of that and add the .dlls
to your application and u can use them for any type of control.

Thanks

Alternatively, you could create a templateField for the fields you want to validate, and use an ASP.NET validator control in that templateField. I've had that work without issue...

It does require knowledge of templateFields. Fortunately MSDN has good documentation on them:

http://www.asp.net/learn/data-access/tutorial-12-cs.aspx

Thanks! that method worked for me!

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.