User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 423,510 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,701 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1936 | Replies: 3
Reply
Join Date: Feb 2007
Posts: 29
Reputation: aravindkishore is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
aravindkishore aravindkishore is offline Offline
Light Poster

select check boxes

  #1  
Jul 16th, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Location: Bellevue, WA
Posts: 1,548
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Rep Power: 8
Solved Threads: 51
Sponsor
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: select check boxes

  #2  
Jul 16th, 2007
Show some effort. It's one of the rules.
Reply With Quote  
Join Date: Jun 2007
Posts: 14
Reputation: sasindagi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
sasindagi sasindagi is offline Offline
Newbie Poster

Re: select check boxes

  #3  
Jul 17th, 2007
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" /
Reply With Quote  
Join Date: Aug 2006
Location: India
Posts: 812
Reputation: arjunsasidharan is on a distinguished road 
Rep Power: 4
Solved Threads: 13
arjunsasidharan's Avatar
arjunsasidharan arjunsasidharan is offline Offline
Practically a Posting Shark

Re: select check boxes

  #4  
Jul 17th, 2007
please use codetags. Its quite difficult to read
There is just two ways to live your life.
One is as though nothing is a miracle.
The other is as if everything is.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 4:32 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC