服務(wù)熱線
153 8323 9821
投票程序,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; //選中第一項