做了一个简单的投票~从数据库的两个表中读出投票的主题及相对应的选项~但是点击radiobuttonlist中的一个~选择投票按键~实现的结果是数据库中相对应的选项应该加1~但是总是不能实现~想问各位高手怎么解决~投票按键中的代码如下:
        SqlConnection Conn = new SqlConnection("server=.;database=hotel;uid=sa");
        string dd = this.Request.QueryString["ID"].ToString();
        string sql = "select ID,detail,num from votedetail where itemid='" + dd + "'";
        SqlDataAdapter Comm = new SqlDataAdapter(sql, Conn);
        DataSet ds = new DataSet();
        Comm.Fill(ds, "votedetail");
        RadioButtonList1.DataSource = ds.Tables["votedetail"].DefaultView;
        RadioButtonList1.DataTextField = "detail";
        RadioButtonList1.DataValueField = "ID";
        RadioButtonList1.DataBind();        int count3 = Convert.ToInt16(ds.Tables[0].Rows[0]["num"]) + 1;
        string newsql = "update votedetail set num='" + count3.ToString() + "' where ID='" + this.RadioButtonList1.SelectedValue + "'";
        SqlCommand comm = new SqlCommand(newsql, Conn);
        Conn.Open();
        comm.ExecuteNonQuery();
        Conn.Close();
        Response.Write("<script> alert('投票成功!')</script>");其他都没有问题~就是where ID='" + this.RadioButtonList1.SelectedValue + "'这里出了问题~
所以点击投票按键~数据库的信息没有更新~

解决方案 »

  1.   

    this.RadioButtonList1.SelectedValue没值,还是?
      

  2.   

    RadioButtonList里面的按钮有2个属性:Text和Value,你是不是只设置了Text(显示的属性),而没有设置Value属性
    如:
    <asp:ListItem Value="Value 1" Text="Item 1">Inner 1</asp:ListItem>
    你检查是否设置了 Value属性
      

  3.   

    RadioButtonList1的value有没有绑定啊?? 
      

  4.   

         public void dataBind()
        { //绑定选项
            SqlConnection Conn = new SqlConnection("server=.;database=hotel;uid=sa");
            string dd = this.Request.QueryString["ID"].ToString();
            string sql = "select ID,detail,num from votedetail where itemid='" + dd + "'";
            SqlDataAdapter Comm = new SqlDataAdapter(sql, Conn);
            DataSet ds = new DataSet();
            Comm.Fill(ds, "votedetail");        RadioButtonList1.DataSource = ds.Tables["votedetail"].DefaultView;
            RadioButtonList1.DataTextField = "detail";
            RadioButtonList1.DataValueField = "ID";
            RadioButtonList1.DataBind();
    这里面RadioButtonList1.DataValueField = "ID";是绑定value啊~
    this.RadioButtonList1.SelectedValue的值就是我选择的那个选项~选项是从数据库里读出来的~不是固定的~
      

  5.   

    this.RadioButtonList1.SelectedValue 这个是一个变量名啊~
    请高手指教啊~
      

  6.   

    this.RadioButtonList1.SelectedValue 这个怎么是变量名呢
    是radiobutton的属性值,控件有text属性,用来给外界显示的,value是用来后台处理的时候的值,就是前台的text对应的value,可以设置一样,也可以不一样,一般text是文本,value是编号之类的
      

  7.   

    <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
                DataTextField="aaid" DataValueField="aaname" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                <asp:ListItem></asp:ListItem>
                <asp:ListItem></asp:ListItem>
                <asp:ListItem></asp:ListItem>
                <asp:ListItem></asp:ListItem>
                <asp:ListItem></asp:ListItem>
            </asp:RadioButtonList> protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Response.Write(RadioButtonList1.SelectedValue);
        }
    你跟踪看一下this.RadioButtonList1.SelectedValue有没有值呢,是不是正确的值呢
    还有啊,你的数据库的id是什么类型,是int还是varchar,整型没有单引号
      

  8.   

    首先是要给RadioButtonList1进行数据绑定的
    指定它的DataTextField 和DataValueField 
    然后才能用this.RadioButtonList1.SelectedValue来获取选定项的ID