(调查问卷)被选则的项与提交数据库的不一样??
数据库中的表:index int ,name nchar(10),count int.
C#程序如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Drawing.Imaging;
public partial class _Default : System.Web.UI.Page
{
private SqlConnection conn;
private DataSet ds = new DataSet();
private string conString= ConfigurationSettings.AppSettings["conString"];
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack )
{
BindData();
}
}
private void BindData()
{
conn =new SqlConnection(conString );
//创建sql语句
string sql = "select *from city";
//创建datadpater
SqlDataAdapter da = new SqlDataAdapter(sql,conn );
//填充dataset
da.Fill(ds ,"Data");
//给RadioButtonList赋数据
InitRadioButtonList();
DataResult();
}
int cityCount=0;
private void DataResult()
{
foreach (DataRow aRow in ds.Tables["Data"].Rows)
{
cityCount += int.Parse(aRow["count"].ToString());
}
this.Label3.Text = "一个有" + cityCount + "人参加调查";
}
private void InitRadioButtonList()
{
this .RadioButtonList1 .DataSource =ds.Tables ["Data"];
this.RadioButtonList1.DataTextField = ds.Tables["Data"].Columns["name"].ToString();
this.RadioButtonList1.DataValueField = ds.Tables["Data"].Columns["count"].ToString();
this.RadioButtonList1.DataBind();
}
//投票
protected void Button1_Click(object sender, EventArgs e)
{
if (this.RadioButtonList1.SelectedItem != null)
{
conn = new SqlConnection(conString );
conn.Open();
string sql = "update city set count=" +Convert .ToInt32 ( int.Parse(this.RadioButtonList1.SelectedValue) + 1) + " where name='" + this.RadioButtonList1.SelectedItem.Text +"'";
SqlCommand cmd = new SqlCommand(sql ,conn );
this.Label2.Text = "你选择了" + this.RadioButtonList1.SelectedItem.Text;
cmd.ExecuteNonQuery();
conn.Close();
this.Label2.Visible = true;
this.Label3.Visible = false;
BindData();
}
}
//查看结果
protected void Button2_Click(object sender, EventArgs e)
{
this.Label3.Visible = true;
}
}
问题:有时我选择第二项时,它提交的是第一项的答案.还有调查的结果用百分比显示,怎么实现. --------------------编程问答-------------------- 一个劲顶接分
补充:.NET技术 , C#