back up codes

always have a backup of your code

Archive for the tag “enable”

enable/disable dropdownlist

The following code will disable the control:


Public Sub disabledddl(ByVal cs As ControlCollection)
Dim d As Control
For Each d In cs
If TypeOf d Is DropDownList Then
CType(d, DropDownList).Enabled = False
End If
disabledddl(d.Controls)
Next
End Sub

The following code will enable the control


Public Sub enabledddl(ByVal cs As ControlCollection)
Dim d As Control
For Each d In cs
If TypeOf d Is DropDownList Then
CType(d, DropDownList).Enabled = True
End If
disabledddl(d.Controls)
Next
End Sub

Then call the sub routine as:


enabledddl(Me.Controls)
disabledddl(Me.Controls)

enable disable a textbox

The following function will enable a textbox control:


Public Sub enabledtextbox(ByVal myCollection As ControlCollection)
Dim myControl As Control
For Each myControl In myCollection
If TypeOf myControl Is TextBox Then
CType(myControl, TextBox).ReadOnly = False
End If
enabledtextbox(myControl.Controls)
Next
End Sub

This function will disable the textbox:


Public Sub disabledtextbox(ByVal myCollection As ControlCollection)
Dim myControl As Control
For Each myControl In myCollection
If TypeOf myControl Is TextBox Then
CType(myControl, TextBox).ReadOnly = True
End If
disabledtextbox(myControl.Controls)
Next
End Sub

enable/disable checkbox inside gridview

This code will check/uncheck and enable/disable a checkbox inside a gridview, depending if data is already found on database.

Insert the following code on the DataBound event of the gridview control:

For Each myRow As GridViewRow In myGrid.Rows
Dim thechkbx As CheckBox = CType(myRow.FindControl("myChkbx"), CheckBox)
Dim myID As String = myGrid.DataKeys(myRow.RowIndex).Value
command = New Data.SqlClient.SqlCommand("SELECT * FROM MY_TABLE WHERE MY_PK = '" & myID & "'", connection)
reader = command.ExecuteReader()
If reader.Read() Then
thechkbx.Enabled = True
thechkbx.Checked = True
Else
thechkbx.Enabled = False
thechkbx.Checked = False
End If
reader.Close()
Next

Post Navigation

Follow

Get every new post delivered to your Inbox.