locked
selecting multiple radiobuttons from one radiobutton list RRS feed

  • Question

  • User775589824 posted

    What I have is a radio Button List outside of a datagrid and then multiple radiobuttonlists that show up in a datagrid.  What i am trying to accomplish is that when I pick on the one outside the datagrid it will will in the ones in the datagrid per what was picked.  The 3 options are IDT, AT and SAD with values of 1, 2, 3 the same ones in datagrid.  But I still want the ones in datagrid to change if not every person is on same status.  Here is my HTML.  Don't know hwo to begin on code behind other than a selected change event.

    <td width="25%"></td>
    <td width="10%"><asp:label ID="lblMark">Mark Status (All)</asp:label></td>
    <td width="33%"><asp:RadioButtonList ID="rblDutyStatus" RepeatDirection="Horizontal" Runat="server" AutoPostBack="True">
          <asp:ListItem Value="1">IDT</asp:ListItem>
          <asp:ListItem Value="2">AT</asp:ListItem>
          <asp:ListItem Value="3">SAD</asp:ListItem>
    </asp:RadioButtonList></td>
    <td><input id="btnAll" style="DISPLAY: none; WIDTH: 80px; COLOR: blue" onclick="javascript:checkAll(true);"
    type="button" value="Check All" name="btnAll" runat="server"></td>
    </tr>
    </table>

    <table width="100%">
    <tr>
    <td align="center"><asp:datagrid id="myDataGrid" runat="server" BorderWidth="1px" CellPadding="6" GridLines="Both"
    BorderColor="#404040" Font-Size="12px" Font-Names="Verdana,Arial,sans-serif" AutoGenerateColumns="False"
    cellspacing="0" Width="50%"><AlternatingItemStyle BackColor="#b0c4de"></AlternatingItemStyle>
    <HeaderStyle Font-Bold="True" ForeColor="White" BackColor="steelblue"></HeaderStyle>
    <Columns>
    <asp:TemplateColumn HeaderText="Duty Status" ItemStyle-HorizontalAlign="Center">
          <ItemTemplate>
          <asp:radiobuttonlist id="rblStatus" runat="server" Width="80px" RepeatDirection="Horizontal" Font-Size="8">
                <asp:ListItem Value="1">IDT</asp:ListItem>
                <asp:ListItem Value="2">AT</asp:ListItem>
                <asp:ListItem Value="3">SAD</asp:ListItem>
          </asp:radiobuttonlist>
          </ItemTemplate>
          </asp:TemplateColumn>
                <asp:BoundColumn DataField="sidstrNAME_IND" HeaderText="Full Name"></asp:BoundColumn>
                <asp:BoundColumn DataField="sidstrGR_ABBR_CODE" HeaderText="Rank"></asp:BoundColumn>
                <asp:BoundColumn DataField="sidstrSSN_SM" HeaderText="SSN">
                      <HeaderStyle Wrap="False"></HeaderStyle>
                </asp:BoundColumn>
                <asp:BoundColumn DataField="theCheckBox" HeaderText="Attendance"></asp:BoundColumn>
          </Columns>
          </asp:datagrid></td>
          </tr>
          </table>

    Tuesday, June 3, 2008 12:17 PM

Answers

  • User-1703611609 posted

    I used this:  http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

     

    Protected Sub rblDutyStatus_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) 
        For i As Integer = 0 To myDataGrid.Items.Count - 1 
            Dim rbl1 As RadioButtonList = DirectCast(myDataGrid.Items(i).FindControl("rblStatus"), RadioButtonList) 
            For j As Integer = 0 To rbl1.Items.Count - 1 
                rbl1.Items(j).Selected = False 
                If rblDutyStatus.Items(j).Selected Then 
                    rbl1.Items(j).Selected = True 
                End If 
            Next 
        Next 
    End Sub 
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 3, 2008 4:03 PM

All replies

  • User-1703611609 posted

    I am looking into it but i have to ask.  why are you using radio buttons if you want to allow this?? 

    <td><input id="btnAll" style="DISPLAY: none; WIDTH: 80px; COLOR: blue" onclick="javascript:checkAll(true);"
    type="button" value="Check All" name="btnAll" runat="server"></td> 

    Tuesday, June 3, 2008 1:25 PM
  • User775589824 posted

    The check all javascript feature is for checkboxes that are on the same page.  they are used for attendance.  I have put some radiobuttonlist in the datagrid but I have one that sits outside at top of the radiobuttonlist, that when I check a specific radiobutton I want the ones in the datagrid to change as well or they can be changed individually as well.

    Tuesday, June 3, 2008 1:54 PM
  • User-1703611609 posted

    ok that makes more sense.  by the way as a retired member of the national guard, I am proud to be helping you.  I am getting close to an answer i think too.

    Tuesday, June 3, 2008 1:59 PM
  • User-1703611609 posted

    Ok here is the code.

     

    <asp:RadioButtonList ID="rblDutyStatus" RepeatDirection="Horizontal" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="rblDutyStatus_SelectedIndexChanged">
                      <asp:ListItem Value="1">IDT</asp:ListItem>
                      <asp:ListItem Value="2">AT</asp:ListItem>
                      <asp:ListItem Value="3">SAD</asp:ListItem>
                </asp:RadioButtonList>
     
    protected void rblDutyStatus_SelectedIndexChanged(object sender, EventArgs e)
        {        
            for (int i = 0; i < myDataGrid.Items.Count;i++ )
            {
                RadioButtonList rbl1 = (RadioButtonList)myDataGrid.Items[i].FindControl("rblStatus");
                for (int j = 0; j < rbl1.Items.Count;j++ )
                {
                    rbl1.Items[j].Selected = false;
                    if (rblDutyStatus.Items[j].Selected)
                    {
                        rbl1.Items[j].Selected = true;
                    }
                }
            } 
        }
     

     

    Tuesday, June 3, 2008 2:30 PM
  • User-1187166364 posted

    Well i think you cannot do tihs using radiobuttonlist,

    <asp:radiobuttonlist id="rblStatus" runat="server" Width="80px" RepeatDirection="Horizontal" Font-Size="8">
                <asp:ListItem Value="1">IDT</asp:ListItem>
                <asp:ListItem Value="2">AT</asp:ListItem>
                <asp:ListItem Value="3">SAD</asp:ListItem>
          </asp:radiobuttonlist>

    because radio button has a an unique property, which is , when more then one radio button shares same name.. then only can be activated.. and as a matter of fact.. main purpose of radio list is to have only one select.. because at the post back form controls are posted with their name only.. and one time they can have only one vale.. so how can 1 name can have more then 1 value..

    Below you can see rendered version of radiobuttonlist which is quoted on your name.. you can clearly have a look that each and every radio have same name.

    <table id="rblDutyStatus" border="0">
    	<tr>
    		<td>
                        <input id="rblDutyStatus_0" type="radio" name="rblDutyStatus" value="1" onclick="javascript:setTimeout('__doPostBack(\'rblDutyStatus$0\',\'\')', 0)" />
                        <label for="rblDutyStatus_0">IDT</label>
                    </td>
                    <td>
                        <input id="rblDutyStatus_1" type="radio" name="rblDutyStatus" value="2" onclick="javascript:setTimeout('__doPostBack(\'rblDutyStatus$1\',\'\')', 0)" />
                        <label for="rblDutyStatus_1">AT</label>
                    </td>
                    <td>
                        <input id="rblDutyStatus_2" type="radio" name="rblDutyStatus" value="3" onclick="javascript:setTimeout('__doPostBack(\'rblDutyStatus$2\',\'\')', 0)" />
                        <label for="rblDutyStatus_2">SAD</label>
                    </td>
    	</tr>
    </table>
     BUt if you still want to do this.. then use check box list... and to select all check boxes you can have lot's and lot's of code over the google....[:)]
    Tuesday, June 3, 2008 3:28 PM
  • User-1703611609 posted

    my code worked perfectly for me

    Tuesday, June 3, 2008 3:51 PM
  • User-1703611609 posted

    and you dont need to use that damn javascript crap

    Tuesday, June 3, 2008 3:52 PM
  • User775589824 posted

    I take it the language you wrote is C#, if so, I will see if I can translate over to VB tonight.

    Tuesday, June 3, 2008 3:58 PM
  • User-1703611609 posted

    I used this:  http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

     

    Protected Sub rblDutyStatus_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) 
        For i As Integer = 0 To myDataGrid.Items.Count - 1 
            Dim rbl1 As RadioButtonList = DirectCast(myDataGrid.Items(i).FindControl("rblStatus"), RadioButtonList) 
            For j As Integer = 0 To rbl1.Items.Count - 1 
                rbl1.Items(j).Selected = False 
                If rblDutyStatus.Items(j).Selected Then 
                    rbl1.Items(j).Selected = True 
                End If 
            Next 
        Next 
    End Sub 
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 3, 2008 4:03 PM
  • User775589824 posted

    This works spectacular, thank you very much.  Even better I have a code translator now.  I pick a ton of stuff of net that is c# and translate it.

    Wednesday, June 4, 2008 8:49 AM
  • User775589824 posted

    BTW, thanks for your service and support.

    Wednesday, June 4, 2008 8:51 AM