访问动态RadioButtonList数组对象 [英] Accessing a dynamic RadioButtonList array object

查看:121
本文介绍了访问动态RadioButtonList数组对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了RadioButtonList类的数组,但显然似乎无法访问它或使用从中检索到的答案.

我总是得到一个例外:对象引用未设置为对象的实例.

I''ve created an array of RadioButtonList class, but apparently can''t seem to access it or use the answer retrieved from it.

I always get the exception: Object reference not set to an instance of an object.

protected void Button5_Click(object sender, EventArgs e)
{


    RadioButtonList[] RBLPain = new RadioButtonList[2];





        RBLPain[0] = new RadioButtonList();


        RBLPain[0].Items.Add("Yes");

        RBLPain[0].Items.Add("No");

        Panel1.Controls.Add(RBLPain[0]);



            if (RBLPain[0].SelectedItem.Text == "Yes")
            {
               Response.Write(RBLPain[0].SelectedItem.Text);
            }


    }




任何帮助将不胜感激,谢谢您:)




Any help would be appreciated thanks :)

推荐答案

您可以像这样更改代码,添加一个判断:
you can alter your code like this , add a judgment :
ifRBLPain[0].SelectedItem != null)
{
  if (RBLPain[0].SelectedItem.Text == "Yes")
   {
       Response.Write(RBLPain[0].SelectedItem.Text);
   }
}


如果您还有其他疑问,请告诉我.


if you have a doubt else, let me know.


这篇关于访问动态RadioButtonList数组对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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