我如何...访问转发器中分组的radiobutton值[asp.net,c#] [英] How do I...access radiobutton value grouped in repeater [asp.net, c#]
问题描述
如何访问转发器中使用的单选按钮的检查值。 [使用asp.net和C#],
数据从sql server数据库填充。
< asp:Repeater ID =rptProfession runat =server>
< itemtemplate>
<%#DataBinder.Eval(Container,DataItem.DescE )%>
<%#DataBinder.Eval(Container,DataItem.DescA)%>
< asp:RadioButton id =rdbUserrunat =server OnClick =javascript:SelectSingleRadiobutton(this.id)/>
C#代码背后按钮:
public void Submit_Evaluation(Object s,EventArgs e)
{
foreach(rptProfession.Items中的RepeaterItem项目)
{
if(item.ItemType == ListItemType.Item) || item.ItemType == ListItemType.AlternatingItem)
{
RadioButton rb =(RadioButton)item.FindControl(rdbUser) ;
if(rb.Checked)
{
pbadErrorMessage =Good;
}
if(!rb.Checked)
{
pbadErrorMessage =Bad;
}
}
}
How can i accessed check value of radio button used in repeater. [using asp.net and C#],
Data is populated from sql server database.
<asp:Repeater ID="rptProfession" runat="server" >
<itemtemplate>
<%# DataBinder.Eval(Container, "DataItem.DescE")%>
<%# DataBinder.Eval(Container, "DataItem.DescA")%>
<asp:RadioButton id="rdbUser" runat="server" OnClick="javascript:SelectSingleRadiobutton(this.id)" />
C# Code Behind Button:
public void Submit_Evaluation(Object s, EventArgs e)
{
foreach (RepeaterItem item in rptProfession.Items)
{
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
RadioButton rb = (RadioButton) item.FindControl("rdbUser");
if (rb.Checked)
{
pbadErrorMessage = "Good";
}
if (!rb.Checked)
{
pbadErrorMessage = "Bad";
}
}
}
推荐答案
您应该使用 - RepeaterItem.FindControl方法 [ ^ ]。
首先找出RepeaterItem
,然后通过传递控件ID $ c来使用
FindControl
$ c>。
You should use - RepeaterItem.FindControl Method[^].
First find out theRepeaterItem
, then useFindControl
by passing theControl ID
.
只需将DataBind代码放入Page_Init过程,这样就可以在到达Page_Load过程时设置无线电按钮的状态。
并设置单选按钮的AutoPostBack =true。
工作正常....
Just Putting DataBind code in the Page_Init procedure, that way the state of the radiobuttons will be set by the time it reaches the Page_Load procedure.
and Set AutoPostBack="true" of Radio Button.
Its work fine....
这篇关于我如何...访问转发器中分组的radiobutton值[asp.net,c#]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!