Repeater: How to create radiobutton or get selected value from repeater in

rain1178 used Ask the Experts™
I would like to ask regarding the question above. I created a repeater in a webform. However, i want to get what value selected by the user.

Why i cannot use the follwing code to create radiobutton?

Private Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.
RepeaterItemEventArgs) Handles Repeater1.ItemDataBound

   If e.Item.ItemType = ListItemType.AlternatingItem Or
                e.Item.ItemType = ListItemType.Item Then
            Dim r As Label
            Dim s As String
            r = e.Item.FindControl("Label1")
            s = "<input type=radio name='myradiogroup'
                  value=" & Trim(e.Item.DataItem(0)) & ">"
            r.Text = s
        End If
End Sub

The error msg appear is :
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:
Line 56:             r = e.Item.FindControl("Label1")
Line 57:             s = "<input type=radio name='myradiogroup' value=" & Trim(e.Item.DataItem(0)) & ">"
Line 58:             r.Text = s
Line 59:         End If
Line 60:     End Sub
Note: The error line is Line 58.

But this code can be use in creating radiobutton in datagrid.

So,anyone can teach me how to correct the code above or other ways to get user's selected value.

Thank you!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
i am not sure about Radio Button as to why u gettign that exception but similar thing i have done for getting selected value from Repeater.
I have kept the id or the value which i need on selection in table cell and set its style to display none and on the click of that row i ahev retrieved the innertext of that  particualr cell, soemthing like
<asp:repeater id="UserListCtrl" runat="server">
<table id='Tabel1' class="OverviewTableBody"  cellSpacing=0 cellPadding=0  border=0>
<tr onclick="javascript:getDetails()"  height="10">
<TD  width="10" height="10"  >
<%# DataBinder.Eval(Container.DataItem, "ID") %>

getDetails() is javascript function
function getDetails()
ID = event.srcElement.parentElement.cells(3).innerText;

Hope this helps you
- Savita


Thank you for ur answer. However, i am not quite understand ur solution. What is "OverviewTableBody" class about? As for the getDetails function,how can i get the selected value and display? How to display the list of value in order to let user to select?

If the selected value can be get through the Javascript function,how i can i use that value in "Behind the code"?

Can u show me the way step by step?
Pls reply me asap!

Thank you!
See in my case i need not display value on server side so i used jaavascript function as i ahd to jsut submit value.

Now i haev tried ur code the only change i ddi in ur code is when u r formign radionbutton in ItemDataBound i think ti shld be :
r = e.Item.FindControl("Label1")
s = "<input type=radio name='myradiogroup'
value=" & Trim(e.Item.Cells(0).Text) & ">"
r.Text = s

-Hope this helps you.
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.



I cannot change the

s = "<input type=radio name='myradiogroup'
value=" & Trim(e.Item.Cells(0).Text) & ">"

because it will return error msg :

Cells is not a member of System.Web.UI.Webcontrols.RepeaterItem

How to solve this problem???
Most Valuable Expert 2012
Top Expert 2008

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


Please leave any comments here within the next seven days.


EE Cleanup Volunteer


PAQed, with points refunded (150)

E-E Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial