Jquery click checkbox

T

tshad

Is there a way to use JQuery to select a checkbox in a GridView object?

You can use it to select rows or highlight rows.

But I am trying to Select a GridRow that I can handle in my C# code later
during postback.

I would like to be able to drag select if possible (Select the rows by
holding down the mouse, drag down a few rows which are highlighted and
select all the boxes that are selected).

Can this be done in JQuery?

I can select a row doing the following but that doesn't check the box.
**********************************************************
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="SelectorTest.aspx.cs" Inherits="MyNamespace.SelectorTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{

$("tr").filter(function()
{
return $('td', this).length && !$('table', this).length
}).click(function()
{
$(this).toggleClass('currRow');
});

});
</script>

<style type="text/css">
.currRow
{
background-color:Gray;
cursor:pointer;
}
</style>

</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
DataKeyNames="CustomerID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID"
ReadOnly="True"
SortExpression="CustomerID" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName"
SortExpression="CompanyName" />
<asp:BoundField DataField="ContactName" HeaderText="ContactName"
SortExpression="ContactName" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City"
SortExpression="City" />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkChoice" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString
%>"
SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName],
[Address], [City] FROM [Customers]">
</asp:SqlDataSource>
</form>
</body>
</html>
************************************************************************

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,039
Messages
2,570,376
Members
47,028
Latest member
IsmaelLans

Latest Threads

Top