GridView - how to make a cell uneditable?

Discussion in 'ASP .Net' started by Steve Kershaw, Sep 19, 2007.

  1. 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?

    Steve Kershaw, Sep 19, 2007
    1. Advertisements

  2. Steve Kershaw

    Sergio E. Guest

    set inertvisible=false
    Sergio E., Sep 19, 2007
    1. Advertisements

  3. Steve Kershaw

    David Wier Guest

    From the Gridview's smart tag, go in and edit the cells - for each column
    you do not want editable, make it's property ReadONLY


    David Wier - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup
    David Wier, Sep 19, 2007
  4. Steve Kershaw

    Monty Guest

    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
    Monty, Sep 19, 2007
  5. 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

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

    Thanks so much for your help!
    Steve Kershaw, Sep 20, 2007
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.