Datagrid Heading (Text - Clickable) and Row Elements (checkboxes) = Select All Feature

Discussion in 'ASP .Net Datagrid Control' started by BTHOMASinOHIO, Nov 10, 2003.

  1. I have spent all day trying to do this and have come up with a
    headache !!

    I have a DataGrid and a couple which is not bound to any data (it's a
    Template Column with all of the column rows as Checkboxes).

    Once the DataGrid is bound, it should allow the user to click on the
    column heading a (through JavaScript or a Server Side function) will
    check or uncheck all of the columns rows checkboxes.

    I have seen may examples of the Heading used for sorting or a checkbox
    in the heading to handle this but this is not what is being asked for.

    1. How can I change the Template Column Heading to a "clickable" Text
    button (if that's possible). (Link button ?!)
     
    BTHOMASinOHIO, Nov 10, 2003
    #1
    1. Advertising

  2. BTHOMASinOHIO

    Matt Guest

    Checkout the event ItemCreated
    and check when the header row is being created.... create a checkbox in the
    cell required.

    this.ItemCreated += new DataGridItemEventHandler(myGrid_ItemCreated);



    private void myGrid_ItemCreated(object sender, DataGridItemEventArgs e)
    {

    if (e.Item.ItemType == ListItemType.Header)
    {
    CheckBox chk = new CheckBox();
    chk.ID = "chkAll";
    chk.Checked = false;
    chk.CssClass = "checkBox";

    e.Item.Cells[3].Controls.Add(chk);
    }
    }

    Matt.


    "BTHOMASinOHIO" <> wrote in message
    news:...
    > I have spent all day trying to do this and have come up with a
    > headache !!
    >
    > I have a DataGrid and a couple which is not bound to any data (it's a
    > Template Column with all of the column rows as Checkboxes).
    >
    > Once the DataGrid is bound, it should allow the user to click on the
    > column heading a (through JavaScript or a Server Side function) will
    > check or uncheck all of the columns rows checkboxes.
    >
    > I have seen may examples of the Heading used for sorting or a checkbox
    > in the heading to handle this but this is not what is being asked for.
    >
    > 1. How can I change the Template Column Heading to a "clickable" Text
    > button (if that's possible). (Link button ?!)
     
    Matt, Nov 13, 2003
    #2
    1. Advertising

  3. BTHOMASinOHIO

    Matt Guest

    I forgot to mention... you need to add:

    chk.AutoPostback = true;

    chk.CheckedChanged += new EventHandler(chk_CheckedChanged);


    to handle the event:

    private void chk_CheckedChanged(object sender, EventArgs e)
    {

    bool checked = ((CheckBox)sender).Checked;

    // do something based on whether the checkbox is checked or not. i.e. run
    through each row and change the Checked property by finding the control in
    the cell.

    CheckBox chk;

    foreach (DataGridItem dgi in myDataGrid.Items)

    {

    if (dgi.ItemType != ListItemType.Header)

    {

    chk = (CheckBox)FindControl("chkDelete");

    if (chk != null)

    chk.Checked = checked;

    }

    }


    "Matt" <> wrote in message
    news:...
    > Checkout the event ItemCreated
    > and check when the header row is being created.... create a checkbox in

    the
    > cell required.
    >
    > this.ItemCreated += new DataGridItemEventHandler(myGrid_ItemCreated);
    >
    >
    >
    > private void myGrid_ItemCreated(object sender, DataGridItemEventArgs e)
    > {
    >
    > if (e.Item.ItemType == ListItemType.Header)
    > {
    > CheckBox chk = new CheckBox();
    > chk.ID = "chkAll";
    > chk.Checked = false;
    > chk.CssClass = "checkBox";
    >
    > e.Item.Cells[3].Controls.Add(chk);
    > }
    > }
    >
    > Matt.
    >
    >
    > "BTHOMASinOHIO" <> wrote in message
    > news:...
    > > I have spent all day trying to do this and have come up with a
    > > headache !!
    > >
    > > I have a DataGrid and a couple which is not bound to any data (it's a
    > > Template Column with all of the column rows as Checkboxes).
    > >
    > > Once the DataGrid is bound, it should allow the user to click on the
    > > column heading a (through JavaScript or a Server Side function) will
    > > check or uncheck all of the columns rows checkboxes.
    > >
    > > I have seen may examples of the Heading used for sorting or a checkbox
    > > in the heading to handle this but this is not what is being asked for.
    > >
    > > 1. How can I change the Template Column Heading to a "clickable" Text
    > > button (if that's possible). (Link button ?!)

    >
    >
     
    Matt, Nov 13, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RJN
    Replies:
    1
    Views:
    1,953
    =?Utf-8?B?U2NvdHQgU2ltb25z?=
    Sep 27, 2004
  2. JB
    Replies:
    3
    Views:
    2,029
    Alexey Smirnov
    Oct 21, 2009
  3. Al Knowles

    How to select all or deselect all checkboxes in datagrid...

    Al Knowles, Dec 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    244
    Al Knowles
    Dec 1, 2003
  4. Matt
    Replies:
    2
    Views:
    217
    Roland Hall
    Jan 11, 2004
  5. Simon Strandgaard
    Replies:
    8
    Views:
    135
    Simon Strandgaard
    Aug 23, 2004
Loading...

Share This Page