数据库名为test.mdb,内有一vote表,字段为:id,title(投票标题),select1(投票项),answer1(计数项),select2,answer2,slect3,answer3,还有一个ischecked(判断是否在前台显示此投票,1为显示,0为不显示),请问这个怎么用radiobuttonlist绑定在前台显示??

解决方案 »

  1.   

    可以这么做
    (1)
    vote字段: id,title,select,ansser,ischecked
    你把所有选项都放大select里,然后用一个分割符隔开,如 很熟|了解|不知道 结果一样的放 results
    49|230|125|300
    读取这样做
    private void display()
    {
    string connstring=System.Configuration.ConfigurationSettings.AppSettings["connstring"]+Server.MapPath("viyo.mdb");
    string sql="select top 1 id,title,items from vote order by addtime DESC";
    OleDbConnection conn=new OleDbConnection(connstring);
    conn.Open();
    OleDbCommand cmd=new OleDbCommand(sql,conn);
    OleDbDataReader reader=cmd.ExecuteReader(); 
    try
    { if(reader.Read())
    {
    this.header.Text="第"+reader.GetValue(0).ToString()+"期:"+reader.GetValue(1).ToString(); //绑定选项
    ArrayList item_text=new ArrayList();
    string[] item_all=reader.GetValue(2).ToString().Split('|');
    foreach(string item in item_all)
    {
    item_text.Add(item);
    }
    this.items.DataSource=item_text;
    this.items.DataBind();
    } }

    catch(Exception e)
    {
    throw e;
    }
    finally
    {
    reader.Close();
    conn.Close();
    }
    }
    至于编辑等,你自己想想。
    (2)
    用两个表
    vote 中放 id,title,ischeck
    select 中放 id,select,answer,vote_id(vote中对应投票期的id)
    这样很明了