Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 12th, 2007, 12:07 AM
Registered User
Join Date: Dec 2006
Location: gurgaon, haryana, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select all checkboxes in a datagrid

i've added checkboxes in the first column of a datagrid which displays 10 records at max. paging is implemented for more than 10 records. a 'Select all' button is there which when pressed select all the checkboxes. similarly, there's a select none button.
action can be performed on the records with selected checkboxes.

i am facing problem when the page index is changed. if i select checkboxes on first page and goto 2nd page, selection is reset.
what i want to do is that when i press select all button, all the records on all the pages should be checked.
i don't know whether this thing is possible or not.
please suggest something.

Reply With Quote
  #2 (permalink)  
Old March 12th, 2007, 06:47 PM
Friend of Wrox
Join Date: Jun 2004
Location: Chennai, Tamil Nadu, India.
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76

I guess you might need to write your own code to implement this. You can invoke the same method in your pageindexchanged event

Find your solution here...
Reply With Quote
  #3 (permalink)  
Old May 7th, 2007, 02:09 PM
lc lc is offline
Registered User
Join Date: May 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Add a ListBox to your form, name it SelectList and set it to visible=false

place this reference to the function below in your page load event:


//keep checkboxes checked/unchked across paging:
private void PersistState ()
    for(int i =0;i<DataGrid1.Items.Count;i++)

        System.Web.UI.WebControls.DataGridItemEventArgs e1 = new DataGridItemEventArgs (DataGrid1.Items[i]);
        //if check box is checked add it
        if(((CheckBox)e1.Item.FindControl("CheckboxSelect" )).Checked)
            string sPK = e1.Item.Cells.Text;//e1.Item.Cells[0].Text + "," + e1.Item.Cells[1].Text + "," + e1.Item.Cells[2].Text ;
            ListItem item=new ListItem(sPK);
                SelectedList.Items.Add(item );
        //if check box is not checked then

            string sPK =e1.Item.Cells.Text; //+ "," + e1.Item.Cells[1].Text + "," + e1.Item.Cells[2].Text ;
            ListItem item=new ListItem(sPK);
            //if un checked item is in the list then remove
                SelectedList.Items.Remove(item );

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Checkboxes in datagrid ractim General .NET 2 September 21st, 2004 05:14 AM
select from 66 tables using checkboxes - how gilgalbiblewheel Classic ASP Databases 29 August 11th, 2004 12:31 AM

All times are GMT -4. The time now is 07:21 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.