CheckBox Itemplate column in a Datagrid

Discussion in 'ASP .Net Web Controls' started by Kulwinder, Oct 20, 2005.

  1. Kulwinder

    Kulwinder Guest

    Hello,

    I've got a checkbox column in a datagrid. In the HeaderTemplate I've got a
    checkbox that, when clicked, should go and and replicate it's checked state
    to all other checkboxes in the same column.
    To facilitate this I've created a wrapper classfor the header checkbox, that
    implements the ITemplate interface, and in the InstantiateIn method I duely
    wire up the checkbox, which is a member variable of the class, to an aevent
    handler for the checkChanged event.
    Now this all works just fine if I'm checking the check box in the header
    row. If I'm unchecking it, the checkchanged event handler doesn't get called.
    Any ideas? I've got Autopostback turned to true for the checkbox in the
    header template.
    Also if I create a second column of checkboxes again with a checkbox in the
    header template, and if one of the header checkboxes is already checked and
    Icheck the second header checkbox, the checkchanged event handler for both
    header checkboxes get executed?!!! I'm completely stumped. Some help would me
    much appreciated. Thanks.
    Kulwinder, Oct 20, 2005
    #1
    1. Advertising

  2. "Kulwinder" wrote:

    > Hello,
    >
    > I've got a checkbox column in a datagrid. In the HeaderTemplate I've got a
    > checkbox that, when clicked, should go and and replicate it's checked state
    > to all other checkboxes in the same column.
    > To facilitate this I've created a wrapper classfor the header checkbox, that
    > implements the ITemplate interface, and in the InstantiateIn method I duely
    > wire up the checkbox, which is a member variable of the class, to an aevent
    > handler for the checkChanged event.
    > Now this all works just fine if I'm checking the check box in the header
    > row. If I'm unchecking it, the checkchanged event handler doesn't get called.
    > Any ideas? I've got Autopostback turned to true for the checkbox in the
    > header template.
    > Also if I create a second column of checkboxes again with a checkbox in the
    > header template, and if one of the header checkboxes is already checked and
    > Icheck the second header checkbox, the checkchanged event handler for both
    > header checkboxes get executed?!!!


    This last sentence suggests that the autopostback for the first checkbox was
    disabled and that it needed the second checkbox to postback the form in order
    for the event to be handled.
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com




    I'm completely stumped. Some help would me
    > much appreciated. Thanks.
    Phillip Williams, Oct 20, 2005
    #2
    1. Advertising

  3. Kulwinder

    Kulwinder Guest

    Hi Phillip,

    Thanks for the reply. Actually no, the autopostback for both checkboxes is
    set to true. An important piece of information I forgot to mention in my
    original posting was that the control structure is as follow...
    A Multipage control contains the datagrid which contains the columns with
    these checkboxes in two of it's header columns.
    Further to your reply, if I click on these items individually, as long as
    I'm checking the checkbox, both postback to the server. But neither postback
    if I'm unchecking them.
    Also if either/both are checked and a postback is caused by some other
    completely unrelated event, the checkchanged eventhandler(s) for the checkbox
    will be called if it is checked.

    Would posting the actual code be helpful?

    Thanks,

    Kulwinder
    Kulwinder, Oct 20, 2005
    #3
  4. "Kulwinder" wrote:

    > Hi Phillip,
    >
    > Thanks for the reply. Actually no, the autopostback for both checkboxes is
    > set to true. An important piece of information I forgot to mention in my
    > original posting was that the control structure is as follow...
    > A Multipage control contains the datagrid which contains the columns with
    > these checkboxes in two of it's header columns.
    > Further to your reply, if I click on these items individually, as long as
    > I'm checking the checkbox, both postback to the server. But neither postback
    > if I'm unchecking them.
    > Also if either/both are checked and a postback is caused by some other
    > completely unrelated event, the checkchanged eventhandler(s) for the checkbox
    > will be called if it is checked.


    How about if you were unchecking them, would any other postback cause the
    eventhandlers to execute?

    >
    > Would posting the actual code be helpful?


    If you can get your code simplified to work on its own without connecting to
    a database or without the need for other components then yes.

    > Thanks,
    >
    > Kulwinder
    >
    >
    Phillip Williams, Oct 20, 2005
    #4
  5. Kulwinder

    Kulwinder Guest

    If the checkboxes are unchecked then a post back caused by some other event
    does not cause the execution of their checkchanged eventhandler.

    I'll see if I can pretty up the code and post it. Do you know of any
    problems with event handling for controls embedded within Multipage control?
    Kulwinder, Oct 20, 2005
    #5
  6. Kulwinder

    Kulwinder Guest

    This is for informational purposes for any future readers.
    My probelm here was trhat I was dynamically generating controls, and hooking
    them up to their respective event handlers. However, I was creating these
    controls during the Page_Load event, which is after the OnInit event and
    after the viewstate gets restored to the server-side controls. Hence since
    the controls were not in existence atr the time when ASP .NET trys to restore
    the viewstate, the actual state of the checkboxes, in this case, were
    incvorrect. To remedy the problem, I moved te creation of the checkboxes and
    the hooking up of the event to the Initialize routine and it now works just
    fine.
    I hope this helps someone.
    Kulwinder, Oct 24, 2005
    #6
    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. Andrea Williams

    Datagrid binding to Itemplate Dropdown box

    Andrea Williams, Aug 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,414
    Andrea Williams
    Aug 5, 2004
  2. Luhar Powell via .NET 247
    Replies:
    0
    Views:
    2,448
    Luhar Powell via .NET 247
    Apr 1, 2005
  3. rodrigo guerra

    accessing values from checkbox created with ITemplate

    rodrigo guerra, Jul 14, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    124
    rodrigo guerra
    Jul 15, 2003
  4. Gregory Rampton

    Convert an MS Access Yes/No column to a checkbox column in C# datagrid

    Gregory Rampton, Aug 6, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    198
    Gregory Rampton
    Aug 6, 2003
  5. marian

    dyanmic checkbox/itemplate/checkedchanged uncheck issue

    marian, Aug 8, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    172
    marian
    Aug 8, 2005
Loading...

Share This Page