Results 1 to 1 of 1

Thread: Read-only column on GridView Row Editing

  1. #1

    Thread Starter
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Read-only column on GridView Row Editing

    Here's how to make a specific gridview column read only when a gridview row editing event has been triggered.
    See RowCreated event on making a gridview column read only.

    vb.net Code:
    1. Protected Sub gvDetails_RowCreated(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvDetails.RowCreated
    2.         For Each cell As TableCell In e.Row.Cells
    3.             If ((Not String.IsNullOrEmpty(cell.Text)) And (cell.Text <> "&nbsp;")) Then
    4.                 Dim fld As BoundField
    5.                 fld = DirectCast(DirectCast(cell, DataControlFieldCell).ContainingField, BoundField)
    6.                 If fld.DataField = "CustomerID" Then
    7.                     fld.ReadOnly = True
    8.                 End If
    9.             End If
    10.         Next
    11.     End Sub

    KGC

    Sample Code: ASP.NET in VB
    - VS 2010
    - ADO.NET Entity Framework
    - Northwinds Database
    Attached Files Attached Files
    Last edited by KGComputers; Jul 20th, 2014 at 11:29 AM.
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width