Thursday, February 7, 2013

Gridview checkbox checked in header by javascript

<%@ Page Language="C#" MasterPageFile="admin.master" Theme="SkinFile" AutoEventWireup="true" CodeFile="deactivepin.aspx.cs" Inherits="cpadmin_deactivepin" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"><
script language="javascript" type="text/javascript">var TotalChkBx;
var Counter;
window.onload =
function(){

//Get total no. of CheckBoxes in side the GridView.TotalChkBx = parseInt('<%= this.GridView1.Rows.Count %>');
//Get total no. of checked CheckBoxes in side the GridView.Counter = 0;
}
function HeaderClick(CheckBox){

//Get target base & child control.var TargetBaseControl = document.getElementById('<%= this.GridView1.ClientID %>');
var TargetChildControl = "chkregno";

//Get all the control of the type INPUT in the base control.var Inputs = TargetBaseControl.getElementsByTagName("input");

//Checked/Unchecked all the checkBoxes in side the GridView.for(var n = 0; n < Inputs.length; ++n)
if(Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl,0) >= 0)Inputs[n].checked = CheckBox.checked;

//Reset CounterCounter = CheckBox.checked ? TotalChkBx : 0;
}
function ChildClick(CheckBox, HCheckBox){

//get target base & child control.var HeaderCheckBox = document.getElementById(HCheckBox);
//Modifiy Counter; if(CheckBox.checked && Counter < TotalChkBx)Counter++;

else if(Counter > 0) Counter--;

//Change state of the header CheckBox.if(Counter < TotalChkBx)HeaderCheckBox.checked =
false;
else if(Counter == TotalChkBx)HeaderCheckBox.checked =
true;}

function confirmMsg(frm){

// loop through all elementsfor (i = 0; i < frm.length; i++){

// Look for our checkboxes onlyif (frm.elements[i].name.indexOf("chkregno") != - 1){

// If any are checked then confirm alert, otherwise nothing happensif (frm.elements[i].checked)
return confirm('Are you sure to Activate Pin ?')}
}
}

</script><
table align="center"><tr><td align="center">
<br />&nbsp;<table align="center" border="0" style="border-right: thin solid; border-top: thin solid;
border-left: thin solid; border-bottom: thin solid; background-color: #eff3fb;"><tr><td colspan="3" class="gradient" >In
Active Pin List
</td></tr><tr><td style="width: 135px; height: 15px;">&nbsp;Type</td><td style="width: 100px; height: 15px;"><asp:DropDownList ID="DropDownList1" runat="server"><asp:ListItem Value="1">Registration</asp:ListItem><asp:ListItem Value="2">5000</asp:ListItem><asp:ListItem Value="3">10000</asp:ListItem><asp:ListItem Value="4">50000</asp:ListItem><asp:ListItem Value="5">100000</asp:ListItem></asp:DropDownList></td><td style="width: 100px; height: 15px;"></td></tr><tr><td style="width: 135px"></td><td style="width: 100px"></td><td style="width: 100px"></td></tr><tr><td style="width: 135px"></td><td style="width: 100px; text-align: center"><asp:Button ID="btnshow" runat="server" OnClick="Button1_Click" Text="Show" Width="82px" /></td><td style="width: 100px"></td></tr><tr><td style="width: 135px"></td><td style="width: 100px; text-align: center"></td><td style="width: 100px"></td></tr><tr><td colspan="3" style="text-align: center"><asp:Label ID="Label1" runat="server" ForeColor="Red" Width="208px"></asp:Label></td></tr><tr><td style="width: 135px"></td><td style="width: 100px; text-align: center"><asp:Button ID="btnsendaward" runat="server" Visible="false" Text="Activate Pin" Width="119px" OnClientClick="return confirmMsg(this.form);" OnClick="btnsendaward_Click" /></td><td style="width: 100px"></td></tr><tr><td colspan="3">&nbsp;</td></tr><tr><td style="width: 135px; height: 16px;"></td><td style="width: 100px; text-align: center; height: 16px;"></td><td style="width: 100px; height: 16px;"></td></tr></table><br /><table align="center" style="border-right: thin solid; border-top: thin solid; border-left: thin solid; border-bottom: thin solid; background-color: #eff3fb"><tr><td style="text-align: right"><asp:Button ID="Button2" runat="server" OnClick="excelreport_Click1" Text="Excel Report" /></td></tr><tr><td style="text-align: right"><asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox1"ErrorMessage="RangeValidator" MaximumValue="500" MinimumValue="1" Type="Integer"ValidationGroup="a">Only Digit!</asp:RangeValidator><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"ErrorMessage="RequiredFieldValidator" ValidationGroup="a">*</asp:RequiredFieldValidator>Enter No Of Record<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="a" Width="47px">50</asp:TextBox><asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="submit" ValidationGroup="a" /></td></tr><tr><td style="text-align: center">&nbsp;<asp:Label ID="Label3" runat="server" Font-Bold="True" Style="left: 1px" Font-Names="Verdana" Font-Size="10pt"></asp:Label>&nbsp;&nbsp;&nbsp;</td></tr><tr><td><asp:GridView ID="GridView1" runat="server" Width="641px" DataKeyNames="pinsrno" AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging"><Columns><asp:TemplateField HeaderText="Sr.No.">
<ItemTemplate> <%
#GridView1.PageIndex*GridView1.PageSize+Container.DataItemIndex+1 %>
</ItemTemplate></asp:TemplateField><asp:BoundField DataField="pinsrno" HeaderText="Pin SrNo" /><asp:BoundField DataField="pinno" HeaderText="Pin No" /><asp:BoundField DataField="pinpassword" HeaderText="Pin Password" /><asp:TemplateField HeaderText="Type">
<ItemTemplate><asp:Label ID="lbltype" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"type") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField><asp:TemplateField>
<ItemTemplate><asp:Label ID="lblcheckid" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"pinsrno") %>' Visible="false"></asp:Label><asp:CheckBox ID="chkregno" runat="server"/></ItemTemplate><HeaderTemplate><asp:CheckBox ID="CheckAll" onclick="HeaderClick(this);" runat="server" /></HeaderTemplate>
</asp:TemplateField><asp:BoundField DataField="amount" HeaderText="Amount" />
</Columns>
</asp:GridView></td></tr></table></td></tr></table></
asp:Content>

No comments:

Post a Comment