投票程序,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; //选中第一项
下一篇:逻辑与运算符 &&
相关新闻
- 小程序登录流程图理解 2020-08-18
- 在C#中获取web.config中的配置信息 2021-08-23
- 小程序open-data头像样式 2021-04-10
- 小程序rich-text 富文本解析图片过大和图片路径的问题 2020-11-25
- C#中去掉字符串的最后一个字符 2020-11-23
 
                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                 
                                                
 
                        
                    
