CheckBox Itemplate column in a Datagrid

K

Kulwinder

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.
 
P

Phillip Williams

Kulwinder said:
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
 
K

Kulwinder

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
 
P

Phillip Williams

Kulwinder said:
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.
 
K

Kulwinder

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?
 
K

Kulwinder

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top