ASP.NET做一个问卷调查系统。DataList中嵌套RadioButtonList和CheckBoxList控件,已经绑定好数据,如何提交

2024-11-15 02:12:08
推荐回答(2个)
回答(1):

怎么绑定的??
RadioButtonList 获取的只有一个值
CheckBoxList 获取的是多个值

给你两个方法参考下

public static class UIMgr
{
///


/// 获取ListControl的值
///

///
///
public static string GetVal(this ListControl list)
{
StringBuilder val = new StringBuilder();
foreach (ListItem li in list.Items)
{
if (!li.Selected) continue;
val.Append(li.Value).Append(",");
}
return val.ToString().TrimEnd(',');
}
///
/// 绑定ListControl的值
///

///
///
public static void BindVal(this ListControl list, string val)
{
string[] valArr = val.Split(',');
foreach (string v in valArr)
{
if (string.IsNullOrEmpty(v)) continue;
ListItem li = list.Items.FindByValue(v);
if (li == null) continue;
li.Selected = true;
}
}
}

回答(2):

RadioButtonList rbl=(RadioButtonList)datalist.control("RadioButtonList1")
这样通过rbl就可以获取RadioButtonList的值,CheckBoxList同理