Q
Problem solve Get help with specific problems with your technologies, process and projects.

Changing a datagrid column to read-only=false based on variable

I have a DataTable that is bound to a datagrid. Is there a way to dynamically change a column in a datagrid from read-only=true to read-only=false when in edit mode based on a variable that has been obtained from a different table? I am using Visual Studio .NET 2003 with Visual Basic and ASP.NET.
The best way to do this is to enable templates on your DataGrid. You can do this by right-clicking on your DataGrid and opening the Property Builder. In the Property Builder, select the Columns item in the list view and change or add Template columns to your DataGrid. When you've added all your template columns, close the Property Builder and right click the DataGrid in your page. Select Edit Template > and select the column you want to edit. Now you can add controls to any of the modes for that column. In your case, you'll probably want a TextBox in the Edit Template. Once you add the TextBox, go to it's property view and select the (DataBindings) property by clicking the [...] button in its property field. This will open the DataBindings form for the TextBox. Select the ReadOnly field from the BindableProperties list and then select the "Custom binding expression" option. You'll want to create an expression that uses the variable you obtained from a different table. For more info on creating custom binding expressions, refer to "Data-Binding Expressions for Web Forms Pages" topic in MSDN.
This was last published in August 2004

Dig Deeper on Win Development Resources

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

TheServerSide.com

SearchCloudApplications

Close