Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid - some columns editable when editing / some read only ?

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
We have a Web Form which makes use of a DataGrid.
The DataView being used as the source for the grid is dynamic (in the sense that the number of columns is variable dependent on factors).
Ideally when the user clicks the 'Edit' button against a grid row - we want some columns to be editable - and some set as read only.
As the data structure is dynamic we can't use the Designer Property Builder to set up the columns (with Read-Only as required).
How can we do this on the fly ?
I.e. we want the (x+2)th, (x+4)th columns to be set as read only.

How can we go about doing this ?
Any help would be appreciated.
Thanks in advance
Steve
 
I have never tried this but you might look into the Item Data Bound Event. If possible, place code in there that if the datasource for the column = x then it is read only. That would be were I would start.

Hope everyone is having a great day!

Thanks - Jennifer
 
Hi again.
We've since (sort of) solved this problem.
We've coded it in such a way that we're setting the property of the underlying DataTable columns to be ReadOnly or not - this then filters through to the DataGrid when we hit edit mode.
Maybe this may help someone else ....
Steve
 
Hi,
just try this to solve this problem.
in the aspx page make the columns as Template columns for which u want editing allowed and let others coumns as bound columns.



Rakhi Kalra
 
I wasn't able to do that as the number of columns was dynamic - the DataTable / DataView being constructed to various conditions prior to getting as far as the grid.
So my only option was to tackle at the source - setting the 'ReadOnly' property against the required fields in the underlying DataTable.
Steve
 
It sounds like you have the problem licked, but I do wonder if it's possible to construct the DataGrid column structure on the fly (setting the EditItemTemplate in the code-behind).

Oh well.
 
You can solve it in the ItemDataBound event of the grid. Have some logic in there that will look at the index of a bound item and suppress the appropriate "edit" button in the row.
 
The problem is that they want to make some columns not editable (in each row).

Actually I should have looked at Steve's post more closely. They found a simple and elegant solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top