DataGrid - Checking one checkbox when the other is clicked

Discussion in 'ASP .Net' started by arun.hallan@gmail.com, Aug 16, 2006.

  1. Guest

    Hi,

    I have two columns in a datagrid that are filled with checkboxes.

    I want one checkbox in a row to be checked when the corresponding
    checkbox is checked.

    I've added an OnCheckedChanged event to the checkbox and implemented
    the method with the following code:

    for (int i = 0; i<this.DataGrid1.Items.Count; i++)
    {
    CheckBox cb=
    (CheckBox)DataGrid1.Items.FindControl("chkContribute");
    if (cb.Checked)
    {
    ((CheckBox)DataGrid1.Items.FindControl("chkPrice")).Checked =
    true;
    }
    }


    Session["CachedSource"] = this.DataGrid;

    But the postback doesnt save the datagrid selections.

    Am i doing this correct and if not is there an easier way?
     
    , Aug 16, 2006
    #1
    1. Advertising

  2. You are probably rebinding the page with each hit, which overwrites the
    click. Move all of your manipulation code into the control events and only
    set the initial load in Page_Load. The viewstate bits happen between init
    and Page_Load and the control events happen after. At that point, you should
    be rebound from viewstate.

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    *************************************************
    Think outside the box!
    *************************************************
    <> wrote in message
    news:...
    > Hi,
    >
    > I have two columns in a datagrid that are filled with checkboxes.
    >
    > I want one checkbox in a row to be checked when the corresponding
    > checkbox is checked.
    >
    > I've added an OnCheckedChanged event to the checkbox and implemented
    > the method with the following code:
    >
    > for (int i = 0; i<this.DataGrid1.Items.Count; i++)
    > {
    > CheckBox cb=
    > (CheckBox)DataGrid1.Items.FindControl("chkContribute");
    > if (cb.Checked)
    > {
    > ((CheckBox)DataGrid1.Items.FindControl("chkPrice")).Checked =
    > true;
    > }
    > }
    >
    >
    > Session["CachedSource"] = this.DataGrid;
    >
    > But the postback doesnt save the datagrid selections.
    >
    > Am i doing this correct and if not is there an easier way?
    >
     
    Cowboy \(Gregory A. Beamer\), Aug 16, 2006
    #2
    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. Replies:
    1
    Views:
    484
    Andy Fish
    Mar 15, 2005
  2. =?Utf-8?B?RG90TmV0RGV2?=

    DataGrid and embeded Checkbox..How to find if checkbox clicked

    =?Utf-8?B?RG90TmV0RGV2?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    831
    David Wier
    Oct 6, 2006
  3. Joey Pang
    Replies:
    4
    Views:
    523
    Joey Pang
    Jun 13, 2005
  4. Michael Champagne
    Replies:
    4
    Views:
    339
    Matt Kruse
    Apr 20, 2004
  5. Rich
    Replies:
    2
    Views:
    105
Loading...

Share This Page