How to make certain rows read-only in DataGrid
Posted on 2007-10-01
If I have a DataTable with one of the columns serving as a flag that I will use to determine if a row should be editable or not, how can I check that flag and then based on that value, make each row either diabled (or just make it not editable would be fine also for each given row) if my flag meets a certain value for a given row. I still want the use to be able to see that row.
I'm not sure where or how to do this and in what DataGrid Event...or if I should just loop through all rows in the Grid right after the line where I perform the DataBind?
I was thinking I could do something like this where cell 0 is my hidden flag field and cell 1 is the edit template cell or something.
Protected Sub dgPhones_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgPhones.ItemDataBound
If e.Item.Cells(0) = myvalue Then
e.Item.Cells(1).Enabled = False