ASP.NET投票系统

要求: 1.上面一张页面的数据要用数据库形式显示 点击投票会跳出下面一张投票的页面 2.实现可以投票的功能 点击投票 弹出上一张页面 但是数据会随便投票改动 点击返回则返回上面一张页面麻烦发到691994251@qq.com 我看过后会给分
2026年09月21日 18:43
有1个网友回答
网友(1):

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection("Data source=localhost;Initial catalog=webvotedb;Persist security info=true;user id=sa");
string sqlstr = "select * from votes";
SqlDataAdapter sda = new SqlDataAdapter(sqlstr, conn);
DataSet ds = new DataSet();
sda.Fill(ds, "votes");
CheckBoxList1.DataSource = ds;
CheckBoxList1.DataTextField = "item";
CheckBoxList1.DataValueField = "voteid";
CheckBoxList1.DataBind();
}
}

这样就可以了,
应为页面回发服务器以后又会执行一次代码,加载事件的代码再次被执行,你之前选的就会消失,下面判断的时候就会一个都没选中,就这样了