从数据库中查到一条数据
TypeContent
男|女,Property=True,Default=我查出来这条数据,我若想把“男 女”存到radioButtonList中应该怎么做????
再有radioButtonList的后置代码中:
想这样实现:radioButtonList.DataSource=“”
我应该怎么做,有没有人给我写个函数获取”男“、“女”值的,
因为它还可能有多个,不如:aa|bb|cc|dd等
感激不尽, 在线等回复!!!!
TypeContent
男|女,Property=True,Default=我查出来这条数据,我若想把“男 女”存到radioButtonList中应该怎么做????
再有radioButtonList的后置代码中:
想这样实现:radioButtonList.DataSource=“”
我应该怎么做,有没有人给我写个函数获取”男“、“女”值的,
因为它还可能有多个,不如:aa|bb|cc|dd等
感激不尽, 在线等回复!!!!
radioButtonList.DataSource=“你的方法”;
//指定显示的列
RadioButtonList1.DataTextField = "这里填写字段名 这个最好保存后台索引,也就是主键 ";
RadioButtonList1.DataValueField = "这里填写显示的字段名 这个用于页面显示的";
radioButtonList.databind();
<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可取得)
} }
我要先截取第一个“,”前的字符串,
然后再分割出 男 女 保密 三条数据 赋给RadioButtonList的项
该怎么做???
对头 要分割
Split先split(',')
然后取这个数组的第一个元素在split('|')
{
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可取得)
} }