Jump to content

Checkbox added to table


filipedine

Recommended Posts

Hi People,I am building a web page using VB.NET and ASP.NET. On this page I have 2 tables, the first table has a dropdownbox and button for the user to select the data.On the Formload sub rotine I have a query to the data base in order to populate the dropdownbox on the first table.When the user selects the item on the dropdownbox and click on the Button, a second sub rotine is executed and will display the data on the secon table as well as a "continue" buttonMy example of the code on the 2 sub routine:" Protected Sub Selected_OnClick(ByVal sender As Object, ByVal e As System.EventArgs) 'Criação da tabela Adress Dim tr1 As TableRow Dim tc1 As TableCell Dim tc2 As TableCell Dim tc3 As TableCell Dim tc4 As TableCell Dim tc5 As TableCell Dim tc6 As TableCell 'Go to database Dim conexaoSQL1 As String Dim Cmd1 As SqlCommand Dim oDataRead As SqlDataReader 'Definir a Connection String conexaoSQL1 = ConfigurationManager.AppSettings("ConnectionString") 'Instanciar um novo comando de SQL Cmd1 = New SqlCommand() 'Definir uma nova conxão Cmd1.Connection = New SqlConnection(conexaoSQL1) 'Abrir a conecção Cmd1.Connection.Open() 'adicinar o comando a executar ao objeto cmd Cmd1.CommandText = "MySQL_Comand" 'Activar a execussão de leitura oDataRead = Cmd1.ExecuteReader() 'Ler registo oDataRead.Read() If oDataRead.HasRows Then tr1 = New TableRow tc1 = New TableCell tc2 = New TableCell tc3 = New TableCell tc4 = New TableCell tc5 = New TableCell tc6 = New TableCell Dim rb0 As RadioButton rb0 = New RadioButton rb0.GroupName = "rbAdress" rb0.ID = "rbAdre0" tc1.HorizontalAlign = HorizontalAlign.Center tc1.Controls.Add(rb0) tr1.Controls.Add(tc1) Dim lblDescription0 As Label lblDescription0 = New Label lblDescription0.Text = "Home" lblDescription0.SkinID = "lblContentDesc" lblDescription0.ID = "lblDescription0" tc2.HorizontalAlign = HorizontalAlign.Center tc2.Controls.Add(lblDescription0) tr1.Controls.Add(tc2) Dim lblAdress0 As Label lblAdress0 = New Label lblAdress0.Text = oDataRead.Item("TXT_ADRESS").ToString lblAdress0.ID = "lblAdress0" lblAdress0.SkinID = "lblContentDesc" tc3.HorizontalAlign = HorizontalAlign.Left tc3.Controls.Add(lblAdress0) tr1.Controls.Add(tc3) tbAdress.Controls.Add(tr1) End If 'Close ligaçõesi oDataRead.Close() Cmd1.Connection.Close() End sub" The user then Click on the radio button on table 2 and the clicks on the "continue" button. I then execute the folowing code: "Protected Sub continue_OnClick(ByVal sender As Object, ByVal e As System.EventArgs) Dim rdbutton As String = "rbAdre0" Dim myRadioButton As RadioButton myRadioButton = New RadioButton myRadioButton = CType(tbAdress.FindControl(rdbutton), RadioButton) If myRadioButton.Checked = False Then Response.Redirect("NewTransportProcess2.aspx?SuppId=" & Page.Session.Item("ssSuppId")) End If End Sub"I keep getting the following error "{"Object reference not set to an instance of an object."}" Can any one help me?Thanks Filipe

Link to comment
Share on other sites

It is likely this line that is throwing the error

If myRadioButton.Checked = False Then

This line is returning null because it cannot find the control you are looking for. Either you are calling it wrong or it does not exist.

myRadioButton = CType(tbAdress.FindControl(rdbutton), RadioButton)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...