Check for duplicate Column value before adding new row to ASP.Net GridView using jQuery

Last Reply 7 months ago By pandeyism

Posted 7 months ago

I have a gridview which contains some textboxes, a dropdown and a checkbox. One of the textboxes which contains for number should be unique in the sense that when I add new row, I don’t want the same phone number as entered in the previous row, it should throw up an alert saying that phone number has been entered. 

                <asp:GridView ID="grdnok" ClientIDMode="Static" runat="server" AutoGenerateColumns="False" EmptyDataText="No Records"
                    ShowFooter="True" Style="clear: both;" OnRowDataBound="grdnok_RowDataBound">
                    <Columns>
                        <asp:TemplateField HeaderText="S/n" ItemStyle-Width="10px">
                            <ItemTemplate>
                                <span id="indxid" class="indxno"><%# Container.DataItemIndex+1 %></span>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Name*" ItemStyle-Width="150px">
                            <ItemTemplate>
                                <asp:TextBox ID="txtkinname" Width="150" runat="server" Text='<%# Eval("kinname")  %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Address" ItemStyle-Width="250px">
                            <ItemTemplate>
                                <asp:TextBox ID="txtkinaddr" runat="server" Width="250" Text='<%# Eval("kinaddr")  %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Phone" ItemStyle-Width="150px">
                            <ItemTemplate>
                                <asp:TextBox ID="txtkinphone" Width="150" runat="server" Text='<%# Eval("kinphone")  %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Relationship" ItemStyle-Width="100px">
                            <ItemTemplate>
                                <asp:DropDownList ClientIDMode="Static" Width="250" CssClass="txtkinrelate" ID="txtkinrelate" runat="server" Style="margin: 5px;">
                                    <asp:ListItem Text="-Select-" Value=""></asp:ListItem>
                                </asp:DropDownList>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="% Alloc." ItemStyle-Width="80px">
                            <ItemTemplate>
                                <asp:TextBox ID="txtkinpercent" CssClass="txtkinpercent" Width="80" runat="server" Text='<%# Eval("Kinpercent")  %>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Benef." ItemStyle-Width="30px">
                            <ItemTemplate>
                                <asp:CheckBox ID="chkbenfac" ClientIDMode="Static" runat="server" Checked='<%# Eval("Benfac")%>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Pix" ItemStyle-Width="50px">
                            <ItemTemplate>
                                <asp:Image ID="imgkin" class="imgkin" runat="server" ImageUrl='<%# Eval("Picimg")  %>' Height="50" Width="50" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Upload">
                            <ItemTemplate>
                                <asp:Label ID="imgkinerr" CssClass="imgkinerr" Style="font-size: 10px; color: red; display: none" runat="server">
                                </asp:Label><br />
                                <asp:FileUpload ClientIDMode="Static" ID="fplImgKinpic" CssClass="fplImgKinpic" runat="server" />
                                <asp:HiddenField ID="hdfpicimg" runat="server" ClientIDMode="Static" Value='<%#Eval("picimg")%>' />
                                <asp:HiddenField ID="hdfFileName" runat="server" ClientIDMode="Static" Value='<%#Eval("Kinpic")%>' />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <HeaderStyle BackColor="#465C71" ForeColor="White" />
                </asp:GridView>

This question does not have replies marked as Answer.