Checkboxes checked in runtime datagrid

D

DJ Dev

Hi All,
I have a complex problem. I have dropdownlists (usually 3-5) and the
user selects some value from these and for each value selected,
datagrids are shown to the user. I am creating the Datagrids
dynamically using a loop depending on the number of Dropdownlists. The
datagrids also have a checkbox template column. Now my problem is that
how can I access the values selected by the user from these
checkboxes. He checks one or more checkboxes for each of the datagrid.
I am assigning unique ids to datagrids while creation. When the page
postsback, the datagrid is reconstructed dynamically. Can I use
viewstate or something to get what the user selected before the
datagrid is re-built on postback.
Thanks!
 
K

Ken Cox [Microsoft MVP]

If you need to maintain viewstate in dynamically-created controls, you might
want to look at this free control from Denis Bauer:

"ASP.NET gives a developer the opportunity to programmatically add controls
to a web form using ParentControl.Controls.Add(new Control());
However, these controls are not persisted in any way thus having to be
recreated for each subsequent request. "

http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx
 
J

Jos

DJ Dev said:
Hi All,
I have a complex problem. I have dropdownlists (usually 3-5) and the
user selects some value from these and for each value selected,
datagrids are shown to the user. I am creating the Datagrids
dynamically using a loop depending on the number of Dropdownlists. The
datagrids also have a checkbox template column. Now my problem is that
how can I access the values selected by the user from these
checkboxes. He checks one or more checkboxes for each of the datagrid.
I am assigning unique ids to datagrids while creation. When the page
postsback, the datagrid is reconstructed dynamically. Can I use
viewstate or something to get what the user selected before the
datagrid is re-built on postback.
Thanks!

First, you need to reconstruct the datagrids in the same way as before
the postback (with the same id's) first. Then, automatically, you get
viewstate, and you can handle the user's selections.

After that, you reconstruct the datagrids once more, in whatever
way is appropriate for the new page.
 
D

DJ Dev

Thanks Jos. That is the problem. I construct the datagrid with the
same id's and in the same way. But I still dont see the user
selections. Do I have to save the user selection in view state or
something. I am really confused. I can provide sample code.
Thanks for the help.
 
D

DJ Dev

You can see what I am doing here..

http://67.126.110.21:8080/Project1/Procsel.aspx

http://67.126.110.21:8080/Project1/codebehind.txt

Basically, the user selects something from dropdownlist, choose some
checkboxes and submits. In the submit event handler, I am re-creating
the datagrid, otherwise it wont show up. But when i do that I also
loose the checkboxes selected. how can i capture that before I
recreate the grid. I have also provided the code-behind. please note
that the dropdowns and data-grids are DYNAMIC and created at runtime.
Thanks for the help!
 
J

Jos

DJ said:

These links don't seem to work.
Basically, the user selects something from dropdownlist, choose some
checkboxes and submits. In the submit event handler, I am re-creating
the datagrid, otherwise it wont show up.

Try recreating the datagrid in Page_Load or Page_Init.
In the submit event handler is too late, because viewstate is added before
that.
 

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

Forum statistics

Threads
473,995
Messages
2,570,231
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top