Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 12th, 2007, 12:07 AM
Registered User
 
Join Date: Dec 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select all checkboxes in a datagrid

Hi,
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.

Thanx
Kawal
 
Old March 12th, 2007, 06:47 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

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

Regards
Ganesh
http://ganeshprof.blogspot.com
Find your solution here...
 
Old May 7th, 2007, 02:09 PM
lc lc is offline
Registered User
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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:

PersistState();


//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);
            if(!SelectedList.Items.Contains(item))
            {
                SelectedList.Items.Add(item );
            }
        }
        //if check box is not checked then
        else
        {

            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
            if(SelectedList.Items.Contains(item))
            {
                SelectedList.Items.Remove(item );
            }
        }
}

        }





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





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