Participant
860 Points
498 Posts
Jun 21, 2019 05:50 AM|AddWeb Solution|LINK
Hello geetasks,
Try with this, I hope this will help you.
<div> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript"> function AddRow() { var operator = $("[id*=txtoperator]").val(); var value1 = $("[id*= txtvalue1]").val(); var value2 = $("[id*= txtvalue2]").val(); var total = $("[id*= txttotal]").val(); if (operator != "" && value1 != "" && value2 != "" && total != "") { var gridRows = $("[id *= data_gridview] tr") var isExist = false; gridRows.each(function () { if ($("td:nth-child(1)", $(this)).html() == operator && $("td:nth-child(2)", $(this)).html() == value1 && $("td:nth-child(3)", $(this)).html() == value2 && $("td:nth-child(4)", $(this)).html() == total) { isExist = true; } }); if (!isExist) { row = $("[id*=data_gridview] tr:last-child").clone(true); $("td:nth-child(1)", row).html(operator); $("td:nth-child(2)", row).html(value1); $("td:nth-child(3)", row).html(value2); $("td:nth-child(4)", row).html(total) $("[id*=data_gridview] tbody tr:first").after(row); $("[id*=txtoperator]").val(''); $("[id*= txtvalue1]").val(''); $("[id*= txtvalue2]").val(''); $("[id*= txttotal]").val(''); } else { alert("The Value already Exist "); } } return false; }; </script> <asp:TextBox ID="txtoperator" runat="server" class="myclass" Height="16px" Width="50px" MaxLength="5"></asp:TextBox> <asp:TextBox ID="txtvalue1" runat="server" class="myclass" Height="16px" Width="50px" MaxLength="5"></asp:TextBox> <asp:TextBox ID="txtvalue2" runat="server" class="myclass" Height="16px" Width="50px" MaxLength="5"></asp:TextBox> <asp:TextBox ID="txttotal" runat="server" class="myclass" Height="16px" Width="50px" MaxLength="5"></asp:TextBox> <br /> <br /> <asp:Button ID="btnAddRow" Text="Add Row" runat="server" OnClientClick="return AddRow();" /> <asp:GridView ID="data_gridview" runat="server" /> </div>
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[4] { new DataColumn("Opertor ",typeof(string)), new DataColumn("Value1", typeof(string)), new DataColumn("Value2", typeof(string)), new DataColumn("Result", typeof(string))}); dt.Rows.Add("", "", "", ""); data_gridview.DataSource = dt; data_gridview.DataBind(); } }
Thank you.
Participant
860 Points
498 Posts
Re: gridview no duplicate value should be entered
Jun 21, 2019 05:50 AM|AddWeb Solution|LINK
Hello geetasks,
Try with this, I hope this will help you.
Thank you.