UI Design:-(Default.aspx)
Source Code:-(Default.aspx.cs)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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">
$("[id*=chkhdr]").live("click", function () {
var chkHeader = $(this);
var grid = $(this).closest("table");
$("input[type=checkbox]", grid).each(function () {
if (chkhdr.is(":checked")) {
$(this).attr("checked", "checked");
$("td", $(this).closest("tr")).addClass("selected");
} else {
$(this).removeAttr("checked");
$("td", $(this).closest("tr")).removeClass("selected");
}
});
});
$("[id*=chkChild1]").live("click", function () {
var grid = $(this).closest("table");
var chkhdr = $("[id*=chkhdr]", grid);
if (!$(this).is(":checked")) {
$("td", $(this).closest("tr")).removeClass("selected");
chkhdr.removeAttr("checked");
} else {
$("td", $(this).closest("tr")).addClass("selected");
if ($("[id*=chkChild1]", grid).length == $("[id*=chkChild1]:checked", grid).length) {
chkhdr.attr("checked", "checked");
}
}
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="grdvSelectChallengers" runat="server"
AutoGenerateColumns="False"
Height="16px" Width="300px"
PageSize="5" AllowPaging="True"
onpageindexchanging="grdvSelectChallengers_PageIndexChanging">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkhdr" runat="server" AutoPostBack="true" OnCheckedChanged="chkhdr_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkChild1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Select Challengers
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblchallengename" runat="server" Text='<%# Eval("challengename") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Default.aspx.cs:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
static SqlConnection cn;
static SqlDataAdapter da;
//static DataSet ds;
static DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bindchallengers();
}
}
protected void bindchallengers()
{
string strQuery = "select challengename from challenge";
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
da = new SqlDataAdapter(strQuery,cn);
dt = new DataTable();
//ds = new DataSet();
da.Fill(dt);
grdvSelectChallengers.DataSource = dt;
grdvSelectChallengers.DataBind();
}
protected void chkhdr_CheckedChanged(object sender, EventArgs e)
{
CheckBox ChkBoxHeader = (CheckBox)grdvSelectChallengers.HeaderRow.FindControl("chkhdr");
foreach (GridViewRow row in grdvSelectChallengers.Rows)
{
CheckBox ChkBoxRows = (CheckBox)row.FindControl("chkChild1");
if (ChkBoxHeader.Checked == true)
{
ChkBoxRows.Checked = true;
}
else
{
ChkBoxRows.Checked = false;
}
}
}
protected void grdvSelectChallengers_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
{
grdvSelectChallengers.PageIndex = e.NewPageIndex;
bindchallengers();
}
}
}
Select Challengers | |||
---|---|---|---|
subs | |||
subs1 | |||
sub21 | |||
sub21 | |||
sub21 | |||
|
Source Code:-(Default.aspx.cs)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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">
$("[id*=chkhdr]").live("click", function () {
var chkHeader = $(this);
var grid = $(this).closest("table");
$("input[type=checkbox]", grid).each(function () {
if (chkhdr.is(":checked")) {
$(this).attr("checked", "checked");
$("td", $(this).closest("tr")).addClass("selected");
} else {
$(this).removeAttr("checked");
$("td", $(this).closest("tr")).removeClass("selected");
}
});
});
$("[id*=chkChild1]").live("click", function () {
var grid = $(this).closest("table");
var chkhdr = $("[id*=chkhdr]", grid);
if (!$(this).is(":checked")) {
$("td", $(this).closest("tr")).removeClass("selected");
chkhdr.removeAttr("checked");
} else {
$("td", $(this).closest("tr")).addClass("selected");
if ($("[id*=chkChild1]", grid).length == $("[id*=chkChild1]:checked", grid).length) {
chkhdr.attr("checked", "checked");
}
}
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="grdvSelectChallengers" runat="server"
AutoGenerateColumns="False"
Height="16px" Width="300px"
PageSize="5" AllowPaging="True"
onpageindexchanging="grdvSelectChallengers_PageIndexChanging">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkhdr" runat="server" AutoPostBack="true" OnCheckedChanged="chkhdr_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkChild1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Select Challengers
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblchallengename" runat="server" Text='<%# Eval("challengename") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Default.aspx.cs:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
static SqlConnection cn;
static SqlDataAdapter da;
//static DataSet ds;
static DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bindchallengers();
}
}
protected void bindchallengers()
{
string strQuery = "select challengename from challenge";
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
da = new SqlDataAdapter(strQuery,cn);
dt = new DataTable();
//ds = new DataSet();
da.Fill(dt);
grdvSelectChallengers.DataSource = dt;
grdvSelectChallengers.DataBind();
}
protected void chkhdr_CheckedChanged(object sender, EventArgs e)
{
CheckBox ChkBoxHeader = (CheckBox)grdvSelectChallengers.HeaderRow.FindControl("chkhdr");
foreach (GridViewRow row in grdvSelectChallengers.Rows)
{
CheckBox ChkBoxRows = (CheckBox)row.FindControl("chkChild1");
if (ChkBoxHeader.Checked == true)
{
ChkBoxRows.Checked = true;
}
else
{
ChkBoxRows.Checked = false;
}
}
}
protected void grdvSelectChallengers_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
{
grdvSelectChallengers.PageIndex = e.NewPageIndex;
bindchallengers();
}
}
}
Web.Config File:-
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="conStr" connectionString="user id=Sa;password=123;Database=master;server=localhost"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
</configuration>
Create Table in DB:-
create table challenge(challengeid int constraint prkey primary key identity(100,1),challengename varchar(30),challengeowner varchar(30))
Insert Data in Table in DB:-
insert into challenge(challengename,challengeowner)values('sub21','ssyss')
No comments:
Post a Comment