浏览量: 次
投票程序,RadioButtonList绑定后,刚打开的页面RadioButtonList是没有选中的,怎么使页面一打开默认第一项被选中。
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
SqlConnection con=DB.createCon();
con.Open();
SqlCommand cmd=new SqlCommand("select vTitle from vote where vID="+this.vID+"",con);
this.Label1.Text=Convert.ToString(cmd.ExecuteScalar());
// 在此处放置用户代码以初始化页面
SqlConnection con1=DB.createCon();
con1.Open();
SqlCommand cmd1=new SqlCommand("select vItemID,vItem from voteItem where vID="+this.vID+"",con1);
SqlDataReader sdr=cmd1.ExecuteReader();
this.RadioButtonList1.DataSource=sdr;
this.RadioButtonList1.DataTextField="vItem";
this.RadioButtonList1.DataValueField="vItemID";
this.RadioButtonList1.DataBind();
sdr.Close();
con1.Close();
}
}
回答: 加上this.RadioButtonList1.SelectedIndex = 0; //选中第一项
[声明]本网转载网络媒体稿件是为了传播更多的信息,此类稿件不代表本网观点,本网不承担此类稿件侵权行为的连带责任。故此,如果您发现本网站的内容侵犯了您的版权,请您的相关内容发至此邮箱【27535611@qq.com】,我们在确认后,会立即删除,保证您的版权。