GridView, Checkbox column.

I'm coding an ASP.NET project in VB.NET.  I'm using the GridView control.  It's bound to a data table. The first column of the data table is defined as col0.DataType = System.Type.GetType("System.Boolean").   This manifests itself as a checkbox column in the grid.  From code, I can set the value of the first column in the data table and it is reflected correctly in the grid.  I can loop through the rows in the grid and reference the first column and retrieve the boolean value.  However, the  checkbox column in the grid is always disabled.

How do I enable the  checkbox/boolean column?

Thanks
LVL 1
HLRosenbergerAsked:
Who is Participating?
 
HLRosenbergerAuthor Commented:
This problem is solved as follows:

Dim chk As New CheckBox

            cell = e.Row.Cells(0)
            cell.Width = New Unit("20")
            cell.Enabled = True
            chk.ID = "IsSelected"
            cell.Controls.Add(chk)
0
 
cdaly33Commented:
So you're wanting the grid rows to be editable?  Here's a good article on how to setup an editable grid.
http://msdn.microsoft.com/en-us/library/ms972948.aspx
0
 
HLRosenbergerAuthor Commented:
I'll take a look at it.  I don't want all columns to be editable?   I just want to be able to check and uncheck the checkbox column.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
cdaly33Commented:
You'll have to set the entire grid as editable then mark all other columns readonly.  I'm assuming that you do want to save the value of the checkboxes after they change right?
0
 
HLRosenbergerAuthor Commented:
That works.   Is it easy to set the entire grid as editable?
0
 
cdaly33Commented:
That previous link will create an Edit link to allow a user edit the checkbox.  If you want the entire grid editable when the page loads you will need to use a control other than the asp.net built-in gridview.  Here is an article on bulk edits.
http://blogs.msdn.com/mattdotson/articles/490868.aspx
0
 
HLRosenbergerAuthor Commented:
All I want is a checkbox in a column that allows me to select multiple rows.
0
 
cdaly33Commented:
In your original question you indicated that the checkbox is bound to data.  If you want it to be bound to the data then you'd naturally want to save the changing of the checkboxes.

If it's not bound to the data then forget the edit mode stuff.  Just add an unbound column and in it's item template add a checkbox.


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.