GridView - how to make a cell uneditable?

S

Steve Kershaw

Hi,

I have a gridview with an UpdateQuery() that's fired when the user
edits/updates a row. The problem lies in the fact that every cell in
the edited row shows up as editable even though one cell actually gets
changed in the database.

Is there a way to make a cell appear non-editable?

Thanks
 
M

Monty

If you want more ganular control:

Private Sub grid_RowDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles grdLineItems.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then
If (e.Row.RowState = DataControlRowState.Edit) Or _
(e.Row.RowState = DataControlRowState.Alternate + _
DataControlRowState.Edit) Then
Dim oTxt As TextBox = e.Row.FindControl("txtFoo")
If oTxt IsNot Nothing Then oTxt.Enabled = False
End If
End If
End Sub
 
S

Steve Kershaw

If you want more ganular control:

Private Sub grid_RowDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles grdLineItems.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then
If (e.Row.RowState = DataControlRowState.Edit) Or _
(e.Row.RowState = DataControlRowState.Alternate + _
DataControlRowState.Edit) Then
Dim oTxt As TextBox = e.Row.FindControl("txtFoo")
If oTxt IsNot Nothing Then oTxt.Enabled = False
End If
End If
End Sub









- Show quoted text -

I tried setting the un-editable columns to ReadOnly="true" but when I
actually update through the ObjectDataSource the editable column isn't
updated. It's acting like it dosen't see the data in the
ReadOnly="true" columns. For example:

UPDATE myTable
SET myEdit = :myEdit
WHERE myNonEdit = :myNonEdit (doesn't see myNonEdit because of the
ReadOnly="true")
AND...

Note the ":" instead of the "@" because this is an Oracle (not SQL
Server) database.

Thanks so much for your help!
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top