从asp.net中的动态创建的控件(单选按钮列表)中检索数据 [英] Retrive data from dynamically created control (radio button list) in asp.net

查看:62
本文介绍了从asp.net中的动态创建的控件(单选按钮列表)中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单页面中创建100个问题的测验。成功创建单选按钮列表DYNAMICALLY。但现在问题是如何检索存储在单选按钮列表中的数据。



用于粘贴参考代码以动态创建单选按钮列表



Creating Quiz with 100 Question in single page. Successfully created radio button list DYNAMICALLY. But now problem is how to retrieve the Data stored in radio button list.

For reference code pasted to create radio button list dynamically

protected void Page_Load(object sender, EventArgs e)
   {
       //if (!Page.IsValid) return;

       int n = 100;

       // now, create n TextBoxes, adding them to the PlaceHolder TextBoxesHere
       for (int i = 0; i < n; i++)
       {
           RBLPlaceHolder.Controls.Add(new RadioButtonList());
       }

       // now, set the Text property of each TextBox
       IterateThroughChildren(this);
   }

   void IterateThroughChildren(Control parent)
   {
     foreach (Control c in parent.Controls)
     {
         if (c.GetType().ToString().Equals("System.Web.UI.WebControls.RadioButtonList") &&
             c.ID == null)
       {
         ((RadioButtonList)c).Items.Add("A");
         ((RadioButtonList)c).Items.Add("B");
         ((RadioButtonList)c).Items.Add("C");
         ((RadioButtonList)c).Items.Add("D");
         ((RadioButtonList)c).RepeatDirection = RepeatDirection.Horizontal;
         count++;
       }

       if (c.Controls.Count > 0)
       {
         IterateThroughChildren(c);
       }
     }
   }

推荐答案

使用

var myRBL = this.FindControl(RadioButtonList)为RadioButtonList;
Use
var myRBL = this.FindControl("RadioButtonList") as RadioButtonList;


这篇关于从asp.net中的动态创建的控件(单选按钮列表)中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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