从数据库中查到一条数据
   TypeContent
    男|女,Property=True,Default=我查出来这条数据,我若想把“男 女”存到radioButtonList中应该怎么做????
再有radioButtonList的后置代码中:
想这样实现:radioButtonList.DataSource=“”
我应该怎么做,有没有人给我写个函数获取”男“、“女”值的,
因为它还可能有多个,不如:aa|bb|cc|dd等
感激不尽, 在线等回复!!!!

解决方案 »

  1.   

    没有条件 就直接绑定 直接绑定 用ObjectDataSource 指定一下数据源就可以了 然后在指定显示到radioButtonList的列如果有条件就手动绑定//手动绑定
    radioButtonList.DataSource=“你的方法”;
    //指定显示的列
    RadioButtonList1.DataTextField = "这里填写字段名 这个最好保存后台索引,也就是主键 ";
    RadioButtonList1.DataValueField = "这里填写显示的字段名 这个用于页面显示的";
    radioButtonList.databind();
      

  2.   

    radioButtonList的这2个属性 就是指定显示的字段的  DataTextField  DataValueField 你慢慢玩 记得给分
      

  3.   


        <div>
      <asp:RadioButtonList runat="server" ID="rbnSex">
       
      </asp:RadioButtonList>
        
        </div>后台: protected void Page_Load(object sender, EventArgs e)
            {
                if(!Page.IsPostBack)
                {
                    BindRadioButtonList();
                }
            }
            private void BindRadioButtonList() 
            {
                string ss = "aa|bb|cc|dd";//从数据库中 配置文件中读取
                foreach (string s in ss.Split('|')) 
                {
                    rbnSex.Items.Add(new ListItem(s, s));//前者是显示文本,后者是radioButtonlist绑定的值(通过rbnSex.SelectedValue可取得)
                    
                }        }
      

  4.   

    那倘若我有一个字符串就比如“男|女|保密,aaafdsf,dsfdsfds”
    我要先截取第一个“,”前的字符串,
    然后再分割出 男 女 保密 三条数据 赋给RadioButtonList的项
    该怎么做???
      

  5.   


    对头 要分割
    Split先split(',') 
    然后取这个数组的第一个元素在split('|')
      

  6.   

     private void BindRadioButtonList()
        {
            string ss = "男|女|保密,asdadasd,asdasd";//从数据库中 配置文件中读取
            string[] ary = ss.Split(',');
            foreach (string s in ary.ToArray()[0].Split('|'))
            {
                rbnSex.Items.Add(new ListItem(s, s));//前者是显示文本,后者是radioButtonlist绑定的值(通过rbnSex.SelectedValue可取得)
            }    }
      

  7.   

    PS:如果你能决定的话,尽量别配置类似 男|女|保密,asdadasd,asdasd  这样的东西读取不方便 还容易出错