Geeks With Blogs

News


Rodney Vinyard - .NET & SQL Developer When all is said and done, more will be said than done

Making Rows in an Editable DataGrid Un-Editable

original article by : Scott Mitchell

http://datawebcontrols.com/faqs/Editing/MakingRowsUneditable.shtml

   Private Sub dgSchedules_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgSchedules.ItemDataBound

 

        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

 

            'Columns {templateColumn = 0, Date, Amount, BU_Name, BU_Id = 4}

            Dim bu As String = e.Item.Cells(4).Text

            Dim BU_Id As Integer = CInt(bu)

            Dim objCommon As New CommonFuncs

            Dim isWritable As Boolean = objCommon.BusinessUnitIsWritable(BU_Id)

 

            If Not isWritable Then

                'USER CANNOT EDIT THIS ROW then

                'Hide the Edit column control

                '(not applicable here, we have just text, no control)

                e.Item.Cells(0).Controls(0).Visible = False

                'disable does not work! (looks disabled but you can still click on it!)

                e.Item.Cells(0).Enabled = False

                'do not make invisible (pulls columns from right to left, ugh!)

                'e.Item.Cells(0).Visible = False

                'wipe the "Edit" text instead

                e.Item.Cells(0).Text = ""

                '-------------------------------------------------------------------------------

                'set a custom "hide" Attribute

                '-------------------------------------------------------------------------------

                e.Item.Cells(0).Attributes.Add("hide", "true")

            End If

        End If

    End Sub

    Private Sub CheckOrUncheckTheCheckbox(ByVal Checked As Boolean)

        Dim dataGridItem As DataGridItem

        '-------------------------------------------------------------------------------

        'if not hide attribute, then check/uncheck

        '-------------------------------------------------------------------------------

        For Each dataGridItem In Me.dgLetters.Items

            '-------------------------------------------------------------------------------

            'locate the checkbox

            '-------------------------------------------------------------------------------

            Dim checkBox As CheckBox

            checkBox = dataGridItem.FindControl("cbxSelect")

            '-------------------------------------------------------------------------------

            'locate the Attribute

            '-------------------------------------------------------------------------------

            Dim attrib As String = dataGridItem.Cells(0).Attributes("hide")

            If attrib = "" Then

                'If Not obj Is Nothing Then

                If checkBox.Visible Then

                    checkBox.Checked = Checked

                End If

            Else

                '-------------------------------------------------------------------------------

                'else hide attribute = true, hite the checkBox

                '-------------------------------------------------------------------------------

                checkBox.Visible = False

            End If

        Next

    End Sub

 

Posted on Thursday, January 4, 2007 2:13 PM GridView, Datagrid, DataList & Repeater | Back to top


Comments on this post: Making Rows in an Editable DataGrid Un-Editable

# re: Making Rows in an Editable DataGrid Un-Editable
Requesting Gravatar...
There are few places where you can run across really worthy information.Your post is an excellent example of why I keep coming back to read your excellent quality content that is forever updated.
Left by lucky on Jul 03, 2010 5:18 AM

Your comment:
 (will show your gravatar)


Copyright © Rodney Vinyard | Powered by: GeeksWithBlogs.net