簡體   English   中英

檢查是否選中了單選按鈕並找出哪個

[英]Check if an radio button was checked and finding out which

大家好,周五愉快! :)

1:我正在為學校建立一個 .net 網站,我想建立一個調查,您應該檢查其中一個選項(無線電輸入)並單擊“投票”。

我以這種方式構建了一個表格:

<form runat="server">
    <div id="voteBox">
        <h3 class="heading">Lorem ipsum dolor sit amet</h3>
        <asp:RadioButton runat="server" ID="messi" GroupName="players" /><h5 class="text">מסי</h5>
        <asp:RadioButton runat="server" ID="iniesta" CssClass="iniesta" GroupName="players" /><h5 class="text" style="margin-right: 50px; margin-top: -20px;">איניאסטה</h5>
        <asp:RadioButton runat="server" ID="xavi" CssClass="xavi" GroupName="players" /><h5 class="text" style="margin-right: 50px; margin-top: -20px;">צאבי</h5>
        <asp:RadioButton runat="server" ID="pedro" CssClass="pedro" GroupName="players" /><h5 class="text" style="margin-right: 50px; margin-top: -20px;">פדרו</h5>
        <asp:Button ID="submit" runat="server" Text=" הצבע " cssClass="submitButt" style="margin-top: -10px; margin-right: 210px;" onClick="countVote" />
    </div>
</form>

從這里,我如何才能知道單擊按鈕時是否選擇了其中一個選項,而不是找到 put 選擇的是哪個選項。

2:為了保留服務器中的投票,我想使用應用程序變量。 您能否指導我如何制作這些變量並在選擇和投票時提高它們的價值。

提前謝謝你,伊利亞

如果您使用的是 vb.net,那么您的代碼中將有一個 submit_countVote 子(過程)。 然后,您可以使用下面的代碼:

Protected Sub submit_countVote(Object Sender, EventArgs e)

  if messi.checked then 
      if Application("messi") is nothing then     
         Application("messi") = 0
      end if
    Application("messi") = Cint(Application("messi")) + 1
  End if
  'Repeat for rediobutton
End Sub

盡管您知道內存中有一個計數器,但當應用程序被回收(根據設置每天一次)或崩潰時,此計數器將消失。 您應該尋找將其保存到數據庫的示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM