Validator in gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dotNetDummi
    New Member
    • Nov 2007
    • 9

    #1

    Validator in gridview

    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!

    Code:
    <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>
  • Usharva
    New Member
    • Nov 2007
    • 2

    #2
    Hi,

    sorry i dint understand your code, but i understood your problem. you can just try the below code

    <asp:GridView runat="server" ID="gvMaster" AutoGenerateCol umns="False" HorizontalAlign ="Left"
    CellPadding="0" ForeColor="#333 333" Font-Size="8pt" BorderStyle="Gr oove"
    AllowPaging="Tr ue" PageSize="12" DataKeyNames="i tem_code" Font-Names="Tahoma"
    Font-Underline="Fals e" Width="80%" ShowFooter="Tru e">
    <columns>

    <asp:TemplateFi eld HeaderText="Ema il">
    <EditItemTempla te>
    <asp:TextBox ID="gvEEmail" runat="server" Width="60px"></asp:TextBox>
    <asp:RegularExp ressionValidato r ID="regvEmail" runat="Server" ControlToValida te="gvEEmail" Display="dynami c"
    SetFocusOnError ="true" Font-Names="Tahoma" ValidationExpre ssion="^[\w-\.]+@([\w-]+\.){1,2}[\w-]{2,4}$"
    Font-Size="8pt">Ente r proper mail id</asp:RegularExpr essionValidator >
    </EditItemTemplat e>
    </columns>

    </gridview>

    you can do the same for Footertemplate

    Comment

    Working...