Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to make certain rows read-only in DataGrid

Posted on 2007-10-01
7
Medium Priority
?
1,486 Views
Last Modified: 2008-01-09
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
        End If
    End Sub
0
Comment
Question by:dba123
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:zip001
ID: 19996211
Try to do it on the RowEditing event, as the event argument allows you to cancel the edit

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowediting.aspx

0
 
LVL 1

Expert Comment

by:zip001
ID: 19996220
Oh, one more thing...

From the RowEditing event arguments, there is a property called NewEditIndex

So, you can do something like this to get access to your flag in the datasource

GridView.Rows(e.NewEditIndex).DataItem

If you use a datatable, you can cast this to a datarow and access the flag

Ctype(GridView.Rows(e.NewEditIndex).DataItem, DataRow)("flag")

Hope that this helps :)



0
 
LVL 1

Author Comment

by:dba123
ID: 19998244
That's fine but it requires the user to actually click the edit button.  I don't want that edit button to show up or for it to be disabled so that they can't even click on it.  I want to disable that cell altogether or row altogether...either or.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Expert Comment

by:zip001
ID: 20002305
if you want to delete the row, just implement a filter with a dataview and bind the gridview to the dataview.

If you want to disable the button, try using javascript after the page is loaded
0
 
LVL 1

Accepted Solution

by:
dba123 earned 0 total points
ID: 20003168
figured it out.  You have to do it or can do it in the ItemDataBound.  At this point the items have already been bound to the grid.  I can then check whatever cell there and disable whatever other cell I want
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20042912
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month20 days, 23 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question