| | |
select check boxes
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2007
Posts: 29
Reputation:
Solved Threads: 1
HI everybody,
Please give the example (preferably in C#) for if I select the check box in header template of gridview then it should automatically check the item-template check boxes.
It is very much appreciable if you give the example for datagrid for the same scenario .
Please give the answer.
Thank you,
Aravind.
Please give the example (preferably in C#) for if I select the check box in header template of gridview then it should automatically check the item-template check boxes.
It is very much appreciable if you give the example for datagrid for the same scenario .
Please give the answer.
Thank you,
Aravind.
•
•
Join Date: Jun 2007
Posts: 14
Reputation:
Solved Threads: 0
just copy the code in ur .aspx
1> javscript function
<script language ="javascript" >
function check_uncheck(Val)
{
var ValChecked = Val.checked;
var ValId = Val.id;
var frm = document.forms[0];
// Loop through all elements
for (i = 0; i < frm.length; i++)
{
// Look for Header Template's Checkbox
//As we have not other control other than checkbox we just check following statement
if (this != null)
{
if (ValId.indexOf('CheckAll') != - 1)
{
// Check if main checkbox is checked,
// then select or deselect datagrid checkboxes
if (ValChecked)
frm.elements[i].checked = true;
else
frm.elements[i].checked = false;
}
else if (ValId.indexOf('deleteRec') != - 1)
{
// Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
if (frm.elements[i].checked == false)
frm.elements[1].checked = false;
}
} // if
} // for
} // function</PRE>
function confirmMsg(frm)
{
// loop through all elements
for (i = 0; i < frm.length; i++)
{
// Look for our checkboxes only
if (frm.elements[i].name.indexOf("deleteRec") != - 1)
{
// If any are checked then confirm alert, otherwise nothing happens
if (frm.elements[i].checked)
return confirm('Are you sure you want to delete your selection(s)?')
}
}
}
<script>
2> grid view event
<asp:GridView ID="GridView1" datakeyname="Id" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="Id" Font-Names="Verdana" AllowPaging="True" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" Width="758px">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="CheckAll" onclick="return check_uncheck (this );" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Id" Visible="false"
Text='<%# DataBinder.Eval (Container.DataItem, "Id") %>'
runat="server" />
<asp:CheckBox ID="deleteRec" onclick="return check_uncheck (this );"
runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="ManagerName" SortExpression="Name" />
<asp:BoundField DataField="pone" HeaderText="phone" SortExpression="pone" />
<asp:BoundField DataField="emailid" HeaderText="emailAddress" SortExpression="emailid" />
<asp:BoundField DataField="ManagPass" HeaderText="ManagerPassword" SortExpression="ManagPass" />
<asp:BoundField DataField="Designation" HeaderText="Designation" SortExpression="Designation" />
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True"
SortExpression="Id" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>
3> button event
asp:Button ID="Button1" runat="server" OnClientClick="return confirmMsg(this.form)"
Text="Delete" OnClick="Button1_Click" Width="50px" /
1> javscript function
<script language ="javascript" >
function check_uncheck(Val)
{
var ValChecked = Val.checked;
var ValId = Val.id;
var frm = document.forms[0];
// Loop through all elements
for (i = 0; i < frm.length; i++)
{
// Look for Header Template's Checkbox
//As we have not other control other than checkbox we just check following statement
if (this != null)
{
if (ValId.indexOf('CheckAll') != - 1)
{
// Check if main checkbox is checked,
// then select or deselect datagrid checkboxes
if (ValChecked)
frm.elements[i].checked = true;
else
frm.elements[i].checked = false;
}
else if (ValId.indexOf('deleteRec') != - 1)
{
// Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
if (frm.elements[i].checked == false)
frm.elements[1].checked = false;
}
} // if
} // for
} // function</PRE>
function confirmMsg(frm)
{
// loop through all elements
for (i = 0; i < frm.length; i++)
{
// Look for our checkboxes only
if (frm.elements[i].name.indexOf("deleteRec") != - 1)
{
// If any are checked then confirm alert, otherwise nothing happens
if (frm.elements[i].checked)
return confirm('Are you sure you want to delete your selection(s)?')
}
}
}
<script>
2> grid view event
<asp:GridView ID="GridView1" datakeyname="Id" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="Id" Font-Names="Verdana" AllowPaging="True" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" Width="758px">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="CheckAll" onclick="return check_uncheck (this );" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Id" Visible="false"
Text='<%# DataBinder.Eval (Container.DataItem, "Id") %>'
runat="server" />
<asp:CheckBox ID="deleteRec" onclick="return check_uncheck (this );"
runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="ManagerName" SortExpression="Name" />
<asp:BoundField DataField="pone" HeaderText="phone" SortExpression="pone" />
<asp:BoundField DataField="emailid" HeaderText="emailAddress" SortExpression="emailid" />
<asp:BoundField DataField="ManagPass" HeaderText="ManagerPassword" SortExpression="ManagPass" />
<asp:BoundField DataField="Designation" HeaderText="Designation" SortExpression="Designation" />
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True"
SortExpression="Id" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>
3> button event
asp:Button ID="Button1" runat="server" OnClientClick="return confirmMsg(this.form)"
Text="Delete" OnClick="Button1_Click" Width="50px" /
![]() |
Similar Threads
- Issues with check boxes (Visual Basic 4 / 5 / 6)
- retreive and update from check boxes (ColdFusion)
- Select all check boxes in datgrid by one check box outside thegrid (ASP.NET)
- HTML Form not working with IE when lots of select/option boxes included. (HTML and CSS)
- HTML Form not working with IE when lots of select/option boxes included. (Web Browsers)
- Use Backup to Back Up Files and Folders on Your Computer in Windows XP (Windows tips 'n' tweaks)
- Set Performance Options in Windows XP (Windows tips 'n' tweaks)
- IE6 - dialogue boxes , check boxes and radio buttons work very slowly after hijacking (Viruses, Spyware and other Nasties)
Other Threads in the ASP.NET Forum
- Previous Thread: programming logic test
- Next Thread: asynchronous dropdownlist any idea
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax appliances asp asp.net bc30451 beginner bottomasp.net box browser businesslogiclayer button c# c#gridviewcolumn cac checkbox class click compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownmenu dynamic edit embeddingactivexcontrol fileuploader findcontrol flash flv forms gridview gudi homeedition iframe iis javascript jquery list menu mono mssql multistepregistration nameisnotdeclared novell objects order problem ratings redirect registration relationaldatabases rotatepage save search security serializesmo.table sessionvariables silverlight smartcard sql ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopemnt webdevelopment wizard xml






