繁体   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