如何访问中继器中使用的单选按钮的检查值。 [使用Asp.Net和C#] [英] How Can I Accessed Check Value Of Radio Button Used In Repeater. [Using Asp.Net And C#]

查看:42
本文介绍了如何访问中继器中使用的单选按钮的检查值。 [使用Asp.Net和C#]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从sql server数据库填充数据。



ASP代码

Data is populated from sql server database.

ASP Code

<asp:Repeater ID="rptProfession" runat="server">
  <itemtemplate>
    <asp:RadioButton id="rdbUser" runat="server" />
  </itemtemplate>
</asp:Repeater>



C#代码:按钮后面


C# Code:Behind button

public void Submit_Evaluation(Object s, EventArgs e)
{
  foreach (RepeaterItem item in rptProfession.Items)
  {
    if (item.ItemType == ListItemType.Item)
    {
      RadioButton rb = (RadioButton) item.FindControl("rdbUser"); 
  
      if (rb.Checked)
      {
        lblMessage.Text = "Good";
      }
      else
      {
        lblMessage.Text = "Bad";
      }
    }
}

推荐答案

已完成......

< asp:repeater id =rptProfessionrunat =serverxmlns:asp =#unknown>

< itemtemplate>

< asp :radiobutton id =rdbUserautopostback =truerunat =server>







C#代码:与上面相同。



只需

将DataBind代码放入Page_Init过程,这样无线电按钮的状态将是在到达Page_Load程序时设置。

并设置单选按钮的AutoPostBack =true。
Its done ...
<asp:repeater id="rptProfession" runat="server" xmlns:asp="#unknown">
<itemtemplate>
<asp:radiobutton id="rdbUser" autopostback="true" runat="server">



C# Code: Same as above.

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.


这篇关于如何访问中继器中使用的单选按钮的检查值。 [使用Asp.Net和C#]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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