我如何...访问转发器中分组的radiobutton值[asp.net,c#] [英] How do I...access radiobutton value grouped in repeater [asp.net, c#]

查看:63
本文介绍了我如何...访问转发器中分组的radiobutton值[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 FindControl $ c>。
You should use - RepeaterItem.FindControl Method[^].

First find out the RepeaterItem, then use FindControl by passing the Control 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆