issay
asked on
get selected value of radiobuttonlist dynamically
i have created a radiobuttonlist dynamically and now i want to get the selected value of the list.
here is how i created radiobuttonlist dynamically
here is how i tried to get selected value. but an error occuers
error is: Object reference not set to an instance of an object. on line 2 of second coding
all these codings are done codebehind file.
here is how i created radiobuttonlist dynamically
row = New HtmlTableRow()
cell = New HtmlTableCell
Dim rbl As New RadioButtonList
rbl.ID = "rblID"
rbl.Items.Add(New ListItem("Yes", "1"))
rbl.Items.Add(New ListItem("No", "2"))
rbl.DataBind()
cell.Controls.Add(rbl)
row.Controls.Add(cell)
newtables.Controls.Add(row)
here is how i tried to get selected value. but an error occuers
Dim c As RadioButtonList = DirectCast(FindControl("rblID"), RadioButtonList)
TextBox1.Text = c.SelectedItem.Text
error is: Object reference not set to an instance of an object. on line 2 of second coding
all these codings are done codebehind file.
Have you written the code to create the radiobuttonlist in the Page Load event?
Make sure you check the IsPostBack Condition.
Make sure you check the IsPostBack Condition.
ASKER
P1ST0LPETE:
the way you told also not working. same error occurs.
informaniac:
i have created radiobuttonlist in page load event. i have tried both the ways. but still same error
the way you told also not working. same error occurs.
informaniac:
i have created radiobuttonlist in page load event. i have tried both the ways. but still same error
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
correct anser for my question is
Dim radio1 As RadioButtonList = DirectCast(newtables.FindC ontrol("rb lID"), RadioButtonList)
TextBox1.Text = radio1.SelectedItem.Text
i figure it out by testing several codes
by the ways informaniac:and P1ST0LPETE: idea was helpfull thanks
Dim radio1 As RadioButtonList = DirectCast(newtables.FindC
TextBox1.Text = radio1.SelectedItem.Text
i figure it out by testing several codes
by the ways informaniac:and P1ST0LPETE: idea was helpfull thanks
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
I believe these lines of code would do the trick:
Dim rbl As New RadioButtonList
rbl.ID = "rblID"
rbl.Items.Add(New ListItem("Yes", "1"))
rbl.Items.Add(New ListItem("No", "2"))
rbl.DataBind()
Maybe even just this:
Dim rbl As New RadioButtonList
rbl.ID = "rblID"
An then you should be able to set your textbox value like this:
TextBox1.Text = rbl.SelectedItem.Text