[英]Find HTML radio button inside repeater
In a repeater I have following button: 在转发器中,我有以下按钮:
<input type="radio" name="mainSelection" id="rbtn" />
I want to check on of ratio button as True. 我想将比率按钮检查为True。 So I am doing this
onItemDataBound
Event 所以我正在做这个
onItemDataBound
事件
How Can I find this button on the OnItemDataBount
Event. 如何在
OnItemDataBount
事件上找到此按钮。 RepAddress_OnItemDataBound
This is my code: 这是我的代码:
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;
}
}
}
You cannot do that with pure HTML controls. 您不能使用纯HTML控件来做到这一点。 It's only capable of finding server controls because they are actually present in the controls collection.
它只能找到服务器控件,因为它们实际上存在于控件集合中。
If you want you can convert your HTML radio button to server control using runat
attribute like this:- 如果您愿意,可以使用
runat
属性将HTML单选按钮转换为服务器控件,如下所示:-
<input type="radio" runat="server" name="mainSelection" id="rbtn" />
After this you can find your control in ItemDataBound
like this:- 之后,您可以在
ItemDataBound
找到控件,如下所示:-
HtmlInputRadioButton rb = e.Item.FindControl("rbtn") as HtmlInputRadioButton;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.