2016-02-10 26 views
0

有3個單選按鈕,我需要放置在3個面板內,然後根據用戶登錄情況隱藏。現在的問題是當所有的單選按鈕都可見時。我不能讓用戶只勾選一個。我試過Groupname屬性,但發現沒有運氣。多個面板內的Radiobutton

           <td> 
                <asp:Panel ID="Panel100" runat="server" Visible="True" > 
                 <asp:RadioButtonList ID="cpem13" runat="server" CellPadding="0" CellSpacing="0" Font-Size="X-Small" Height="18px" RepeatDirection="Horizontal" Width="74px" GroupName="B1" > 
                  <asp:ListItem Text="PDA/PPN" Value="5"></asp:ListItem> 
                 </asp:RadioButtonList> 
                </asp:Panel> 
               </td> 
               <td> 
                <asp:Panel ID="Panel102" runat="server" Visible="True" > 
                 <asp:RadioButtonList ID="RadioButtonList1" runat="server" CellPadding="0" CellSpacing="0" Height="18px" RepeatDirection="Horizontal" Width="80px" Font-Size="X-Small" GroupName="B1"> 
                  <asp:ListItem Text="PPP/PPW" Value="0"></asp:ListItem> 
                 </asp:RadioButtonList> 
                </asp:Panel> </td> 
               <td> 
                <asp:Panel ID="Panel103" runat="server" Visible="True" Width="68px" > 
                 <asp:RadioButtonList ID="RadioButtonList2" runat="server" CellPadding="0" CellSpacing="0" Height="16px" RepeatDirection="Horizontal" Width="218px" Font-Size="X-Small" GroupName="B1"> 
                  <asp:ListItem Text="PAE" Value="1"></asp:ListItem> 
                 </asp:RadioButtonList> 
                </asp:Panel> </td> 
+0

你是說,你需要在一個面板單選按鈕代碼..但你正在使用3個面板。製作一個並給組名稱 –

+0

@AnoopLL編輯爲3個面板。謝謝 !要明確我需要它是3個多個面板。每個人都有自己的asp:ListItem – idwell

+0

@idwell請checkmy answer.it適合我。 –

回答

1
<td> 
     <asp:panel id="Panel100" runat="server" visible="True"> 
      <asp:RadioButtonList AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" ID="RadioButtonList1" runat="server" CellPadding="0" CellSpacing="0" Font-Size="X-Small" Height="18px" RepeatDirection="Horizontal" Width="74px" > 
       <asp:ListItem Text="PDA/PPN" Value="5"></asp:ListItem> 
      </asp:RadioButtonList> 
     </asp:panel> 
    </td> 
    <td> 
     <asp:panel id="Panel102" runat="server" visible="True"> 
      <asp:RadioButtonList AutoPostBack="true" OnSelectedIndexChanged ="RadioButtonList2_SelectedIndexChanged" ID="RadioButtonList2" runat="server" CellPadding="0" CellSpacing="0" Height="18px" RepeatDirection="Horizontal" Width="80px" Font-Size="X-Small" > 
       <asp:ListItem Text="PPP/PPW" Value="0"></asp:ListItem> 
      </asp:RadioButtonList> 
     </asp:panel> 
    </td> 
    <td> 
     <asp:panel id="Panel103" runat="server" visible="True" width="68px"> 
      <asp:RadioButtonList AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList3_SelectedIndexChanged" ID="RadioButtonList3" runat="server" CellPadding="0" CellSpacing="0" Height="16px" RepeatDirection="Horizontal" Width="218px" Font-Size="X-Small"> 
       <asp:ListItem Text="PAE" Value="1"></asp:ListItem> 
      </asp:RadioButtonList> 
     </asp:panel> 
    </td> 

,並在後面

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     RadioButtonList2.SelectedIndex = -1; 
     RadioButtonList3.SelectedIndex = -1; 

    } 
    protected void RadioButtonList2_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     RadioButtonList1.SelectedIndex = -1; 
     RadioButtonList3.SelectedIndex = -1; 
    } 
    protected void RadioButtonList3_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     RadioButtonList1.SelectedIndex = -1; 
     RadioButtonList2.SelectedIndex = -1; 
    } 

你可以使用「OnSelectedIndexChanged」事件來實現這一目標

在你的問題