簡體   English   中英

在轉發器中查找HTML單選按鈕

[英]Find HTML radio button inside repeater

在轉發器中,我有以下按鈕:

  <input type="radio" name="mainSelection" id="rbtn" />

我想將比率按鈕檢查為True。 所以我正在做這個onItemDataBound事件

如何在OnItemDataBount事件上找到此按鈕。 RepAddress_OnItemDataBound

這是我的代碼:

protected void RepAddress_OnItemDataBound(object sender, RepeaterItemEventArgs e)
 {
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
   {
    // I cannot use ---> RadioButton rb = (RadioButton)e.Item.FindControl("rbtn");  
   // becuase its not an asp Radio Button.

  //I cannot use--> HtmlGenericControl rb = e.Item.FindControl("rbtn") as HtmlGenericControl;

   if (//some condition)
   {
    rb.Checked = true; // That's the reason I need to find the button.
   }
   else
   {
    rb.Checked = false;
    }
  }
}

您不能使用純HTML控件來做到這一點。 它只能找到服務器控件,因為它們實際上存在於控件集合中。

如果您願意,可以使用runat屬性將HTML單選按鈕轉換為服務器控件,如下所示:-

<input type="radio" runat="server" name="mainSelection" id="rbtn" />

之后,您可以在ItemDataBound找到控件,如下所示:-

HtmlInputRadioButton rb = e.Item.FindControl("rbtn") as HtmlInputRadioButton;

暫無
暫無

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

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