在转发器

时间:2015-08-26 11:18:02

标签: c# asp.net 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;
    }
  }
}

1 个答案:

答案 0 :(得分:1)

使用纯HTML控件无法做到这一点。它只能查找服务器控件,因为它们实际上存在于控件集合中。

如果您需要,可以使用runat属性将HTML单选按钮转换为服务器控件: -

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

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

HtmlInputRadioButton rb = e.Item.FindControl("rbtn") as HtmlInputRadioButton;
相关问题