aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Get Selected Row Values from Gridview on Checkbox Selection

Oct 8, 2012

Here I will explain how to get selected row value based on checkbox selection values in gridview using
JQuery in

In previous posts I explained jQuery Check uncheck all checkboxes in gridview, jQuery Higlight selected Gridview row when checkbox selected, jQuery select header checkbox when all child checkboxes selected
Best jQuery Drag and Drop Plugins and many articles relating to JQuery. Now I will explain how to get selected row value based on checkbox selection values in gridview using JQuery in

To implement this functionality we need to write the code in Default.aspx page like as shown below

<html xmlns="">
<head id="Head1" runat="server">
<title>Get selected row value based on checkbox selection values in gridview using JQuery in</title>
<script type="text/javascript" src="">
<script type="text/javascript">
$(document).ready(function() {
$('#btnGet').click(function() {
var hdntxt = '';
$("input[name$=chkChild]:checked").each(function() {
hdntxt += "," + $(this).next("input[name$=hdnId]").val()
<form id="form1" runat="server">
<asp:GridView ID="gvUserInfo" runat="server" >
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
<asp:CheckBox ID="chkChild" runat="server" />
<asp:HiddenField ID="hdnId" runat="server" Value='<%#Eval("UserName") %>' />
<input type="button" id="btnGet" value="Get Selected Values" /><br /><br />
<b>Select UserNames:</b><label id="lbltxt"/>
Now add following namespaces in codebehind
C# Code

using System;
using System.Data;
using System.Data.SqlClient;
After that add following code in code behind

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
// This method is used to bind gridview from database
protected void BindGridview()
SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB");
SqlCommand cmd = new SqlCommand("select UserName,LastName,Location from UserInformation", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
gvUserInfo.DataSource = ds;

Imports System.Data
Imports System.Data.SqlClient
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
End If
End Sub
' This method is used to bind gridview from database
Protected Sub BindGridview()
Dim con As New SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB")
Dim cmd As New SqlCommand("select UserName,LastName,Location from UserInformation", con)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
gvUserInfo.DataSource = ds
End Sub
End Class

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Unknown said...

this is what i was blindly searching..great and nice job..kamaal kidda..sir ji..

Anonymous said...

hello this is pragya

i got the following error :-

Multiple controls with the same ID 'hdnID' were found. FindControl requires that controls have unique IDs.

Anonymous said...

how can i store label value into a string in cs file??

Anonymous said...

please help me sir, actually i want to move the selected row to another database. for this i need the value of label. how to get that value

অবান্তর e-পত্রিকা said...

how to use the value/text of lbltxt?

indrajith said...

hi it is very useful thanks

Anonymous said...

Dear Sir , Please provide source

Anonymous said...

Most cool! Thank you :)

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.