ASP.NET CheckboxList and checking items in gridview

Hello,

in an edititemtemplate of a gridview representing incidents I placed a checkboxlist. The data I retrieve is a table with the fields ID,Description and Checked for each incident. In the past I used the rowdatabound event to check the listitems manually, but I wonder if there's another (easier) way to do this.

Thank you.
LVL 9
Stephan_SchrandtAsked:
Who is Participating?
 
masterpassConnect With a Mentor Commented:
In the past I used the rowdatabound event to check the listitems manually >>>>> 

The situation still prevails, you have to loop through items to do any checking/unchecking of items. Also, it is the same, if you want to check whether an item is checked or not.
0
 
_Katka_Connect With a Mentor Commented:
Hi, you can create another column with boolean representation, and then display this column instead.

1) you've column myDbBooleanValue (not a boolean column actually)
2) create additional true boolean column myCalculatedBooleanValue, to be bound to a grid

You can then synchronize these two columns calculate via ColumnChanged event directly on the DataTable.

- if myDbBooleanValue is changed from '0' to '1', then myCalculatedBooleanValue is changed to True
- myCalculatedBooleanValue is changed to False, then myDbBooleanValue is changed to '0' (for example)

It would be maybe even better to encapsulate whole data to a class, and then make those changes based on property change.

So, create a class instance from a datatable row. Then bind the object to a grid, when done just generate changes via the object class.

regards,
Kate
0
 
Stephan_SchrandtAuthor Commented:
Thank you for your answer, maybe I did not express myself correctly. My problem is not to get the changes correctly but displaying them while binding the grid to a datasource.
Let's say you want to record phone calls and each call can have one or more categories. When you display a recorded call in your grid, you get a record for the call and n records for the categories. So when you enter edit mode in grid, you have to check some of the categories depending on the second datasource. My first thought was something like 'DataCheckedField' for checkboxlist, similar to the properties 'DataValueField' and 'DataTextField'.
0
 
_Katka_Commented:
In this case, I don't think there's a different way of doing it. It has to be done manually, but you can try:

1) make some helper class to automatize this process or
2) create some descendant that will do it for you (but you'll still need to program it yourself)
3) use different components (usually not for free, BUT we're using DevExpress, and this can't still be automatized)

Sorry, maybe someone will offer you better solution, we solved this by making a descendant of the component to help us automatize the binding process, but still we need to do it manually (even thou it's easier).

regards,
Kate
0
 
Stephan_SchrandtAuthor Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.