Disable RowSelectorColumn checkbox

C

Chip

I'm using Andy Smith's RowSelectorColumn control (great control) and I'm not
sure if this question is generic to all datagrid controls or this particular
one.

Is there a way to disable one of the checkboxes based on data in the grid?
If so, can you provide the syntax?

Thanks,
Chip
 
S

Scott Mitchell [MVP]

I'm using Andy Smith's RowSelectorColumn control (great control) and I'm
not
sure if this question is generic to all datagrid controls or this particular
one.

Is there a way to disable one of the checkboxes based on data in the grid?
If so, can you provide the syntax?

If you need to take some action for a DataGrid based on the data in the
row, you need to create an event handler for the DataGrid's ItemDataBound
event. There you can check the data, programmatically reference the
checkbox, and then, based on the data, fiddle with the checkbox (or
whatever Web control in the row you're interested in).


** IN THE DATAGRID'S ITEMDATABOUND EVENT HANDLER... **

If e.Item.ItemType = ListItemType.Item or e.Item.ItemType =
ListItemType.AlternatingItem then
'Reference the RowSelectorColumn checkbox (note, it is an
HtmlInputCheckBox class instance,
'and NOT a CheckBox class instance
Dim myCB As HtmlInputCheckBox =
CType(e.Item.Cells(CELLINDEX).Controls(0), HtmlInputCheckBox)

'Check the data
Dim someColumnValue as String = CType(DataBinder.Eval(e.Item.DataItem,
"SomeColumnName"), String)

If someColumnValue = "someValue" then
myCB.Enabled = False
End If
End If



Hope this helps! Also you might find my book, ASP.NET Data Web Controls
Kick Start to be of interest in amassing further knowledge about the
DataGrid, DataList, and Repeater Web controls.

Happy Programming!

--

<shameless plug>
For more information on the DataGrid, DataList, and Repeater controls,
consider picking up a copy of my latest book:

ASP.NET Data Web Controls
http://www.amazon.com/exec/obidos/ASIN/0672325012/4guysfromrollaco
</shameless plug>

Happy Programming!

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 

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,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top