Hi,
I am getting this error (Object reference not set to an instance of an object.) at
lbl_variant_option_selected.InnerText = rbl.SelectedItem.Attributes("variant_name")
when i try to show selected item from radiobuttonlist. Any idea?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
createRBLcontrols()
End Sub
Private Sub createRBLcontrols()
Dim rbl As New RadioButtonList
rbl.ID = "rbl_product_option1"
rbl.Items.Add("Red")
rbl.Items(0).Attributes.Add("variant_name", "Red")
rbl.Items.Add("Blue")
rbl.Items(1).Attributes.Add("variant_name", "Blue")
rbl.Items(0).Selected = True
Dim titleDiv As New System.Web.UI.HtmlControls.HtmlGenericControl("div")
titleDiv.ID = "titleDiv"
titleDiv.InnerHtml = "<div class=""wrap"">Color: <span id='lbl_variant_option_selected' runat='server'>Red</span></div>"
Me.ContainerRBL.Controls.Add(titleDiv)
rbl.RepeatDirection = RepeatDirection.Horizontal
rbl.AutoPostBack = True
AddHandler rbl.SelectedIndexChanged, AddressOf SelectedIndexChanged_rbl
Me.ContainerRBL.Controls.Add(rbl)
End Sub
Private Sub SelectedIndexChanged_rbl(ByVal sender As Object, ByVal e As EventArgs)
For i As Integer = 0 To Me.ContainerRBL.Controls.Count - 1
Dim lbl_variant_option_selected As System.Web.UI.HtmlControls.HtmlGenericControl = CType(Me.FindControl("lbl_variant_option_selected"), System.Web.UI.HtmlControls.HtmlGenericControl)
Dim rbl As RadioButtonList = Me.ContainerRBL.FindControl("rbl_product_option1")
If IsNothing(rbl) = False Then
lbl_variant_option_selected.InnerText = rbl.SelectedItem.Attributes("variant_name")
End If
Next
End Sub