德育量化管理系统_班级学生德育积分学分考核评价管理系统_天晓网络

以“德”服人——服务于人民

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

学会“FindControl”方法
————————————————————————————————————————————————
http://community.csdn.net/Expert/topic/3527/3527189.xml?temp=.3558313
我是在服务器端循环连续产生了很多TextBox控件,控件的ID为循环变量i值
我记录了i的最大值
我在服务端怎么通过i变量去取得每个控件中输入的值?

int max = 10;
for (int i = 0; i < max; i++)
{
   TextBox textBox = FindControl("prefix" + i.ToString());
   if (textBox  != null)
   {
        string str = textBox.Text; //  取值
    // 在做些其他的事情.
   }
}
+++++++++++++++++++++————————————————————————————————————
法2:

   int i;
   for(i=1;i<=100;i++)
   {
    System.Web.UI.Control control = Page.FindControl("CheckBox" + i.ToString());
    
    if(control!=null)
    {
     //
//    }
   }

————————————————————————————————————————————————
http://community.csdn.net/Expert/topic/3340/3340380.xml?temp=.2531397
我在Page_load事件中动态地创建了一个radiobuttonlist,我在一个按钮事件中执行用于得到此控件的值代码,为什么不能得到我想要的预期结果呢?源代码如下:
page_load事件代码:
   RadioButtonList hirb=new RadioButtonList();
   hirb.ID="lx";
   hirb.RepeatDirection=RepeatDirection.Horizontal;
   hirb.Font.Size=FontUnit.Point(12);
   for(int r=0;r<4;r++)
    hirb.Items.Add(r.ToString());
   Page.FindControl("lx3").Controls.Add(hirb);//lx3为当前页的ID
   hirb.Visible=true;
按钮事件代码:
   Response.Write(((RadioButtonList)Page.FindControl("lx3").FindControl("lx")).SelectedItem.Value);
请各位帮忙解决一下,谢谢!

其实他这个方法可以获取。我获取到了。
有人说“动态的控件随着页面的PostBack会丢失除非你再次声称”
RadioButtonList hirb=new RadioButtonList();
   hirb.ID="lx";
   hirb.RepeatDirection=RepeatDirection.Horizontal;
   hirb.Font.Size=FontUnit.Point(12);
   for(int r=0;r<4;r++)
    hirb.Items.Add(r.ToString());
   Page.FindControl("lx3").Controls.Add(hirb);//lx3为当前页的ID
   hirb.Visible=true;

不要放在!IsPostBack里

不知道是不是,反正我没有,但可以获取。

——————————————————————————————————————————————————————
我的解决方案:
   for (i=1;i<=3;i++)
   {
    RadioButtonList rbl=(RadioButtonList)Page.FindControl("rbl"+i.ToString());
    if (rbl.SelectedIndex<0)
    {
     Response.Write("<script>alert('Wrong"+i.ToString()+"');</script>");
    }
    else
    {
     Response.Write(rbl.SelectedItem.Value+" ");
    }
   }

posted on 2004-12-26 21:58  Tmouse  阅读(1184)  评论(0编辑  收藏  举报