ASP.Net Global Radio Button in Repeater

Hello Experts,

I am working on an ASP.Net helpdesk application for our company intranet, and am running into a problem.  I am trying to include a radio button in a repeater control, and initially ran into the issue of the radio buttons not being mutually exclusive (ie, I could select more than one).  After doing some checking, I found an article referencing a custom class that would provide the function I need (written by Andy Smith, http://metabuilders.com/Tools/DataControlFields.aspx).  I have copied the .dll file to the bin directory in my application's folder, and added the reference to the control in my page.  When I add the GlobalRadioButton control to my page, it now enforces the selection of only one option.  However, when I try to reference the control in a function, it is not available.  I believe this is because it is contained within the repeater control.  How do I reference the GlobalRadioButton control in a function so that I can retrieve its value?  On a broader note, I am a relatively new ASP.Net programmer, with some previous experience in VB 6 and "classic" ASP.  In doing searches for help, I commonly see references to terms like code behind, private void, and others that are unfamiliar.  I am also looking for suggestions on good instructional materials (web sites, books, etc.) to get more up to speed on ASP.Net.  Any and all suggestions are welcome and appreciated!

Thanks,

Russ
<%@ Page Language="VB" debug="true"%>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Register TagPrefix="mbwebcont" Namespace="MetaBuilders.WebControls" Assembly="MetaBuilders.WebControls" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
   
    Sub Page_Load(s As Object, e As EventArgs)
        Dim strPassedName, strSupportTech As String
        strSupportTech = Session(strPassedName)
        Dim strGetOpenIssues As String
        Dim conGetOpenIssues As OleDbConnection
        Dim cmdGetOpenIssues As OleDbCommand
        Dim dtrGetOpenIssues As OleDbDataReader
        strGetOpenIssues = "SELECT Request_ID, User_Full_Name, Contact_Number, Issue_Title, Issue_Type, Issue_Impact, Request_Creation_Time FROM "
        strGetOpenIssues = strGetOpenIssues & "tblSupportRequest WHERE Request_Closed = False"
        conGetOpenIssues = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Inetpub\wwwroot\HelpDesk\Database\database.accdb;Persist Security Info=False")
        cmdGetOpenIssues = New OleDbCommand(strGetOpenIssues, conGetOpenIssues)
        conGetOpenIssues.Open()
        dtrGetOpenIssues = cmdGetOpenIssues.ExecuteReader
        rptOpenIssues.DataSource = dtrGetOpenIssues
        rptOpenIssues.DataBind()
        conGetOpenIssues.Close()
        conGetOpenIssues = Nothing
        cmdGetOpenIssues = Nothing
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="company_helpdesk.css" />
</head>
<body>
<center>
    <form id="frmAddressIssue" runat="server">
    <asp:Table ID="main_table" runat="server" width="650" cellpadding="0" cellspacing="0" border="0" BorderColor="red">
        <asp:TableRow>
            <asp:TableCell HorizontalAlign="Left" VerticalAlign="Top" CssClass="Text_Normal">
                The issues listed below are all issues that are currently listed as open and unassigned in the database.  The issues are sorted by level of impact and time 
                received.  To accept an issue, select the option marker associated with the issue and click the button labeled "Accept Issue" at the bottom of the screen.  
            </asp:TableCell>    
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell Height="7" CssClass="Text_Short">&nbsp</asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell>
                <asp:Repeater ID="rptOpenIssues" runat="server">
                    <HeaderTemplate>
                            <table width="650" border="0" bordercolor="blue" cellpadding="3" cellspacing="0" frame="void">
                                <tr>
                                    <td colspan="4" class="Text_Normal" align="left">These requested records are shown below.</td>
                                </tr>
                                <tr>
                                    <td colspan="4" height="5" class="Text_Short">&nbsp</td>
                                </tr>
                                <tr>
                                    <th class="Text_Normal" align="left" valign="top"><u>Select:</u></th>
                                    <th class="Text_Normal" align="left" valign="top"><u>User:</u></th>
                                    <th class="Text_Normal" align="left" valign="top"><u>Number:</u></th>
                                    <th class="Text_Normal" align="left" valign="top"><u>Issue:</u></th>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td class="Text_Normal" align="left" valign="top">
                                    <mbwebcont:GlobalRadioButton runat="server" ID="radIssues" GlobalGroup="true" GroupName="radAvailIssues"  value='<%#Container.DataItem("Request_ID")%>' />  
                                </td>
                                <td class="Text_Normal" align="left" valign="top"><%#Container.DataItem("User_Full_Name")%></td>
                                <td class="Text_Normal" align="left" valign="top"><%#Container.DataItem("Contact_Number")%></td>
                                <td class="Text_Normal" align="left" valign="top"><%#Container.DataItem("Issue_Title")%></td>
                            </tr>
                        </ItemTemplate>
                        <FooterTemplate>
                            </table>
                        </FooterTemplate>
                </asp:Repeater>
            </asp:TableCell>
        </asp:TableRow>
        </asp:Table>
        <asp:Label ID="lblTest" runat="server" CssClass="Text_Normal"></asp:Label>
    </form>
    </center>
</body>

Open in new window

rdillionSystems AdministratorAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
I just tested a simplified version of your code (with asp radio button) and following code works for me

        For i As Integer = 0 To rptOpenIssues.Items.Count - 1
            Dim rb = rptOpenIssues.Items(i).FindControl("radAvailIssues")
        Next


To be able to extract any properties, you would need to cast rb to correct type like below

Dim grb As GlobalRadioButton = CType(rb, GlobalRadioButton)
0
 
CodeCruiserCommented:
You have to access it using the FindControl function but you need to have a row reference.

Repeater1.Items(RowIndex).FindControl("controlname").Text = ""
0
 
rdillionSystems AdministratorAuthor Commented:
CodeCruiser,
Thanks for the quick reply and help.  By row reference, do you mean I need to find the index number of the row to be selected (ie 0, 1, etc)?  
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
CodeCruiserCommented:
Yes because the control will be created for each row.
0
 
rdillionSystems AdministratorAuthor Commented:
CodeCruiser,
Thanks again for your help.  I have been trying to get this to work most of the afternoon, with your suggestion and also trying some suggestions found online.  
http://www.codeguru.com/csharp/csharp/cs_controls/custom/article.php/c12371/
(I realize the code for the code behind page in the online article is written in C, I have tried to convert it to vb).  I am not getting very far.  I understand that I would need to use the FindControl method of the repeater control to determine the identity of the radio button control that I need to reference, and then see if I can get the value of the radio button group, but I am running into a number of problems putting it into practice.  For one, how would I konw the row reference number?  If I have, say, 5 rows each with a radio button, I would not know which row to reference in the code.  Also, when I attempt to read the .Text attribute of the control, I receive a message stating that that attribute does not exist for that control.  I am confident that this can be done, but it is proving quite frustrating for me.  If you have any other ideas on what I am missing, please let me know.
Thanks again,
Russ
0
 
CodeCruiserCommented:
I used .Text as an example. For radio button it probably would be .Checked property.

Show me your aspx code and I will try to run it in a demo app.

>For one, how would I konw the row reference number?

If you are trying to find out which one is checked, I would imagine you would loop through all the rows and check the radio button in each row to see if its checked.
0
 
rdillionSystems AdministratorAuthor Commented:
Hey CodeCruiser,
Thanks again for all of your help and willingness to take a look at the code.  Let me see if I can put it through a loop and make any headway, and I will get back to you a bit later this AM.  If I am still stuck I'll take you up on your offier.  If I can find some success, it will go a long way in helping me learn.
I'll be in touch,
Russ
0
 
rdillionSystems AdministratorAuthor Commented:
"waves white flag..."
Hey CodeCruiser, I have not made any headway.  I guess I just do not understand the language as well as I need to yet.  All I am trying to do is to pull some information from a database and display it with a mutually exclusive radio button in a repater control, allowing the user to select a row from the list and then when the Submit button is clicked, get a unique value (Request_ID from the database).  If yoiu do have a chance to take a look at this and give any suggestions it would be very much appreciated.  In order to try it, you would also need the custom class dll file referenced in my original post above.  Thanks again very much!
Russ        help-desk.accdb code.txt
0
 
rdillionSystems AdministratorAuthor Commented:
btw, I know there is not much in the code in the submit button click subroutine in the way of determining the id of the selected control, etc.  I have truly tried a number of approaches and continue to get errors like "the object is not referenced" and others.  Just didn't want you to think that I haven't tried to work it out.  Thanks
0
 
rdillionSystems AdministratorAuthor Commented:
CodeCruiser,
Thank you VERY much!!  I have gotten the page to work as I need it to with your assitance.  I sincerely appreciate your time and help!!
Russ
0
 
CodeCruiserCommented:
Glad to help :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.