Click here to Skip to main content
14,697,231 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to make my gridview's specific rows to readonly which contain "YES" in its column 9 so how can I do that. The data in the grid is coming from the SQL Server database.

<pre>foreach (GridViewRow row in GridView1.Rows)

                if (row.Cells[8].Text == "YES")
                  //How can I make the entire row Readonly


Assuming that 'readonly' means hiding the 'edit' button, go to the row that contains the edit link, and remove it.
Sandeep Mewara 31-Aug-10 15:20pm
Did you even got what CG told? What he suggested was not a joke. Have a look at my answer for full detail! :doh:
Your comment was not at all good inspite of what CG suggested was correct. Let me elaborate a little for you:
Few unsaid facts first:
1. You have tagged your question as ASP.NET
2. You have not mentioned anything of thrid party control so you are using ASP.NET grid only
3. Based on what you are asking, I can safely assume you have not implemented converting a gridrow into edit mode via a double-click or a single-click.
4. Since you have asked that you need to convert the row into readonly mode, this means that row is editable and you are able to edit certain values in it and then save the same.
5. Based on 3, you are left with an 'Edit' button for each row.

Now, little explaination of what CG said:
Use the 'Edit' button of fact 5 above. Access that button and disable or hide it. Now, user would not be able to convert the row into edit mode and thus it is equivalent to readonly mode.


Now few other scenario that you might be up to(which you missed to mention in your question)
Might be you have controls in your Itemtemplate of grid where one can go ahead and put some values. Now, might be you want to disable these controls of Itemtemplate. Assuming your final step is saving the values in DB, you want to convert certain rows into readonly mode. (If you are not saving, then no point!)...
If this is what you are looking for then you need to disable the controls individually. You are already in the row you want to. Go ahead and disable all the controls of that row. You can try to see if you have access to all the controls in a row at once to disable.
Omar Akhtar 2009 31-Aug-10 17:15pm
just do it what you said programatically, where I've left comments.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900