ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Select (Check) duplicate record on CheckBox Check in ASP.Net GridView using C# and VB.Net<p>Hi&nbsp;narasiman,</p> <p>This error means column with name <strong>Select Data</strong> which does not exists in your table.</p> <p>I have modified the code.</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:GridView ID=&#34;GridView1&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34;&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText=&#34;Select Data&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID=&#34;chkSelect&#34; runat=&#34;server&#34; Checked=&#39;&lt;%# Convert.ToBoolean(Eval(&#34;Select Data&#34;)) %&gt;&#39; AutoPostBack=&#34;true&#34; OnCheckedChanged=&#34;CheckedChanged&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField=&#34;Slipno&#34; HeaderText=&#34;Slipno&#34; /&gt; &lt;asp:BoundField DataField=&#34;Product&#34; HeaderText=&#34;Product&#34; /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DataTable dt = GetData(); ViewState[&#34;Data&#34;] = dt; GridView1.DataSource = dt; GridView1.DataBind(); } } private static DataTable GetData() { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;Slipno&#34;, typeof(int)), new DataColumn(&#34;Product&#34;, typeof(string)) }); dt.Rows.Add(10, &#34;NPK&#34;); dt.Rows.Add(10, &#34;NPK&#34;); dt.Rows.Add(12, &#34;UREE&#34;); dt.Rows.Add(25, &#34;ENGRA&#34;); DataColumn selectData = new DataColumn(&#34;Select Data&#34;, typeof(bool)); selectData.DefaultValue = false; dt.Columns.Add(selectData); return dt; } protected void CheckedChanged(object sender, EventArgs e) { GridViewRow selectedRow = (sender as CheckBox).NamingContainer as GridViewRow; string selectedName = selectedRow.Cells[1].Text; DataTable dt = ViewState[&#34;Data&#34;] as DataTable; CheckBox chk = (sender as CheckBox); for (int i = 0; i &lt; dt.Rows.Count; i++) { if (dt.Rows[i][&#34;Slipno&#34;].ToString() == selectedName) { if (chk.Checked) { dt.Rows[i][&#34;Select Data&#34;] = true; } else { dt.Rows[i][&#34;Select Data&#34;] = false; } } } GridView1.DataSource = dt; GridView1.DataBind(); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Dim dt As DataTable = GetData() ViewState(&#34;Data&#34;) = dt GridView1.DataSource = dt GridView1.DataBind() End If End Sub Private Shared Function GetData() As DataTable Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn() {New DataColumn(&#34;Slipno&#34;, GetType(Integer)), New DataColumn(&#34;Product&#34;, GetType(String))}) dt.Rows.Add(10, &#34;NPK&#34;) dt.Rows.Add(10, &#34;NPK&#34;) dt.Rows.Add(12, &#34;UREE&#34;) dt.Rows.Add(25, &#34;ENGRA&#34;) Dim selectData As DataColumn = New DataColumn(&#34;Select Data&#34;, GetType(Boolean)) selectData.DefaultValue = False dt.Columns.Add(selectData) Return dt End Function Protected Sub CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Dim selectedRow As GridViewRow = TryCast((TryCast(sender, CheckBox)).NamingContainer, GridViewRow) Dim selectedName As String = selectedRow.Cells(1).Text Dim dt As DataTable = TryCast(ViewState(&#34;Data&#34;), DataTable) Dim chk As CheckBox = (TryCast(sender, CheckBox)) For i As Integer = 0 To dt.Rows.Count - 1 If dt.Rows(i)(&#34;Slipno&#34;).ToString() = selectedName Then If chk.Checked Then dt.Rows(i)(&#34;Select Data&#34;) = True Else dt.Rows(i)(&#34;Select Data&#34;) = False End If End If Next GridView1.DataSource = dt GridView1.DataBind() End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/H1223Pt.gif" alt="" width="236" height="165" /></span></strong></p>https://www.aspforums.net:443/Threads/107535/Select-Check-duplicate-record-on-CheckBox-Check-in-ASPNet-GridView-using-C-and-VBNet/https://www.aspforums.net:443/Threads/107535/Select-Check-duplicate-record-on-CheckBox-Check-in-ASPNet-GridView-using-C-and-VBNet/Mon, 29 Jul 2019 05:48:55 GMT