C#.net的RadioButtonList默认项怎么弄?
答案:6 悬赏:30
解决时间 2021-03-13 03:55
- 提问者网友:沉默菋噵
- 2021-03-12 05:18
C#.net的RadioButtonList默认项怎么弄?
最佳答案
- 二级知识专家网友:老鼠爱大米
- 2021-03-12 05:58
public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List list = new List();
list.Add(new testClass("是"));
list.Add(new testClass("否"));
rdobtnList.DataSource = list;
rdobtnList.DataTextField = rdobtnList.DataValueField = "result";
rdobtnList.DataBind();
for (int i = 0; i < list.Count; i++)
{
if (list[i].Result == "是")//选中条件
{
rdobtnList.SelectedIndex = i;
break;
}
}
}
}
}
public class testClass
{
private string result;
public string Result
{
get { return result; }
set { result = value; }
}
public testClass(string result)
{
this.result = result;
}
}
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List
list.Add(new testClass("是"));
list.Add(new testClass("否"));
rdobtnList.DataSource = list;
rdobtnList.DataTextField = rdobtnList.DataValueField = "result";
rdobtnList.DataBind();
for (int i = 0; i < list.Count; i++)
{
if (list[i].Result == "是")//选中条件
{
rdobtnList.SelectedIndex = i;
break;
}
}
}
}
}
public class testClass
{
private string result;
public string Result
{
get { return result; }
set { result = value; }
}
public testClass(string result)
{
this.result = result;
}
}
全部回答
- 1楼网友:北方的南先生
- 2021-03-12 11:27
在RadioButtonList里有Value把这个value=‘是’或者‘否’,在cs中写this.RadioButtonList.SelectValue = ‘是',就行啦!
- 2楼网友:洒脱疯子
- 2021-03-12 11:05
RadioButtonList.Items.FindByValue("是").Selected = true;
- 3楼网友:猎心人
- 2021-03-12 09:38
RadioButtonList.Items.FindByValue("是").Selected = true;
RadioButtonList.Items.FindByValue("否").Selected = false;
RadioButtonList.Items.FindByValue("否").Selected = false;
- 4楼网友:夜余生
- 2021-03-12 08:40
RadioButtonList.SelectedValue="是";有时候这样不行.
试下面这个.
ListItem LItem = RadioButtonList.Items.FindByValue("是");
if (LItem != null) LItem.Selected = true;
试下面这个.
ListItem LItem = RadioButtonList.Items.FindByValue("是");
if (LItem != null) LItem.Selected = true;
- 5楼网友:末日狂欢
- 2021-03-12 07:11
radiobuttonlist控件有一个叫Sele
ctIndex的属性,这个个属性就是你选定时的索引值。radiobuttonlist.SelectedIndex
获取值的方法如下
radiobuttonlist1.selecteditem.value
ctIndex的属性,这个个属性就是你选定时的索引值。radiobuttonlist.SelectedIndex
获取值的方法如下
radiobuttonlist1.selecteditem.value
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |