Danish Habib

Danish Habib

  • NA
  • 694
  • 246k

how To disable textbox inside gridview

Jan 1 2015 11:12 PM
How to disable textboxes inside gridview Edititem section based on some condition below is the code which says object reference is not set 

 Private Sub grdUserReport_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdUserReport.RowDataBound


        For Each row As GridViewRow In grdUserReport.Rows
            If row.RowType = DataControlRowType.DataRow Then



                For i As Integer = 1 To row.Cells.Count - 1


                    If row.Cells(i).Controls.OfType(Of TextBox)().ToList().Count > 0 Then


                        ' row.Cells(i).Controls.OfType(Of TextBox)().FirstOrDefault().Visible = isChecked
                        row.Cells(i).Controls.OfType(Of TextBox)().FirstOrDefault().Enabled = True



                    End If

                    Dim country As String = TryCast(row.Cells(0).FindControl("litType"), Label).Text
                    Dim strColumn As String = DataBinder.Eval(e.Row.DataItem, "ControlScr").ToString
                    ' Dim check As String = TryCast(row.Cells(1).FindControl("litStatus"), Label).Text
                    ' Dim txtForboy As String = TryCast(row.Cells(0).FindControl("QTotal"), Literal).Text
                    Dim txtBoxMen As TextBox = TryCast(grdUserReport.HeaderRow.FindControl("QTotal"), TextBox)
                    If country.Trim() = "DQTwoValueInteger.ascx" Then
                        txtBoxMen.Enabled = False

                        row.Cells(1).Controls.OfType(Of TextBox)().FirstOrDefault().Enabled = False
                        row.Cells(9).Controls.OfType(Of TextBox)().FirstOrDefault().Enabled = False
                        row.Cells(10).Controls.OfType(Of TextBox)().FirstOrDefault().Enabled = False
                        row.Cells(6).Controls.OfType(Of TextBox)().FirstOrDefault().Enabled = False
                    End If



                Next

            End If


        Next

    End Sub


Answers (2)