GridView template Column conditionally set to readonly
-
Is there a way to set a Template Column on a GridView to readonly from code behind. Like if test for Admin=true make readonly= false else readonly = true?
-
Answer:
There is no direct way to set Gridview column to readonly. But You can set the controls to readonly that are in that column in RowDataBound event of your Gridivew. e.g. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowState == DataControlRowState.Edit || e.Row.RowState == DataControlRowState.Alternate) { TextBox txt = (TextBox)e.Row.FindControl("ControlID"); txt.ReadOnly = true; } }
BillTetrault at Stack Overflow Visit the source
Other answers
Yes, tap into ItemDataBound event, and for each row, either use a readonly control and an edit control and show/hide the right control for the job, or alternatively disable the edit control. There's no global readonly setting for templates. HTH.
Brian Mains
Related Q & A:
- How to merge datasets in Stata conditionally?Best solution by kb.iu.edu
- How to split column text to another column?Best solution by Stack Overflow
- How To Sort a GridView Column When a Header Is Clicked?Best solution by Stack Overflow
- How to find the column name of the first column with a null value?Best solution by Stack Overflow
- How to change column data's as a separate column wise format in a SQL Server?Best solution by stackoverflow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.