Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. asp.net vb radiobuttonlist object reference

asp.net vb radiobuttonlist object reference

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-net
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    janetb99
    wrote on last edited by
    #1

    I don't know until the page is created how many radiobuttonlists I will need. So, I create them and store the number in a hidden label. But, when I want to get the selection from the radiobuttonlist on postback, I keep getting a object reference error. I've tried finding the control without a findControl, with a findControl and with a master page content reference and findControl. No luck. Any help appreciated...

    Dim myConStr As String = ""
    If lblSidCount.Text <> "0" Then
    Dim x As Integer = 1, y As Integer = Convert.ToInt32(lblSidCount.Text)
    Do While x <= y
    Dim myContent As ContentPlaceHolder = CType(Page.Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
    Dim radConStr As New RadioButtonList
    radConStr = CType(myContent.FindControl("rad" & x.ToString), RadioButtonList)
    myConStr &= radConStr.SelectedItem.Text & "~"
    x = x + 1
    Loop
    myConStr = Left(myConStr, Len(myConStr) - 1)
    End If

    J 1 Reply Last reply
    0
    • J janetb99

      I don't know until the page is created how many radiobuttonlists I will need. So, I create them and store the number in a hidden label. But, when I want to get the selection from the radiobuttonlist on postback, I keep getting a object reference error. I've tried finding the control without a findControl, with a findControl and with a master page content reference and findControl. No luck. Any help appreciated...

      Dim myConStr As String = ""
      If lblSidCount.Text <> "0" Then
      Dim x As Integer = 1, y As Integer = Convert.ToInt32(lblSidCount.Text)
      Do While x <= y
      Dim myContent As ContentPlaceHolder = CType(Page.Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
      Dim radConStr As New RadioButtonList
      radConStr = CType(myContent.FindControl("rad" & x.ToString), RadioButtonList)
      myConStr &= radConStr.SelectedItem.Text & "~"
      x = x + 1
      Loop
      myConStr = Left(myConStr, Len(myConStr) - 1)
      End If

      J Offline
      J Offline
      janetb99
      wrote on last edited by
      #2

      This seems to work - am I crazy for doing this? Private radCon As RadioButtonList() Protected Overrides Sub OnInit(ByVal e As EventArgs) MyBase.OnInit(e) If (Request("str") = 1) Then Dim myList As dsSql = New dsSql() ''''instantiate the function to get dataset Dim ds As New Data.DataSet ds = myList.dsConSessionTimes(Request("eid")) If ds.Tables("conSessionTimes").Rows.Count > 0 Then radCon = New RadioButtonList(ds.Tables("conSessionTimes").Rows.Count - 1) {} Dim i As Integer = 0 Dim rad As RadioButtonList = New RadioButtonList() rad.ID = "rad" + i.ToString() rad.DataSource = ds.Tables("conSessions") rad.DataTextField = ds.Tables("conSessions").Columns("session_name").ToString rad.DataBind() rad.SelectedIndex = 0 phConcurrent.Controls.Add(rad) radCon(i) = rad For Each j As Data.DataRow In ds.Tables("conSessionTimes").Rows Dim rad As RadioButtonList = New RadioButtonList() rad.ID = "rad" + i.ToString() rad.DataSource = ds.Tables("conSessions") rad.DataTextField = ds.Tables("conSessions").Columns("session_name").ToString rad.DataBind() rad.SelectedIndex = 0 phConcurrent.Controls.Add(rad) radCon(i) = rad i = i + 1 Next End If End If End Sub

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups