单选框投票程序
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; public partial class vote : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { string s = "select * from people"; DataTable dt = SQLHelper.ExecuteDataTable(s); //设置数据源 RadioButtonList1.DataSource = dt; //设置要显示数据源的字段 RadioButtonList1.DataTextField = "peopleName"; //设置要显示字段对应的值 RadioButtonList1.DataValueField = "peopleId"; //绑定数据 RadioButtonList1.DataBind(); } } catch(Exception ex) { Response.Write(ex.Message); } } protected void btnvote_Click(object sender, EventArgs e) { try { string txt = RadioButtonList1.SelectedItem.Text; string id = RadioButtonList1.SelectedValue; string sql = "update people set Num=Num+1 where peopleId=" + id; SQLHelper.NonExQuery(sql); Response.Write("投票成功!"); } catch (Exception ex) { Response.Write(ex.Message); } } }