zoukankan      html  css  js  c++  java
  • 单选框投票程序

    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);
            }
          
        }
    }
  • 相关阅读:
    4.JDBC技术
    3.MySQL数据库
    2.Oracle数据库
    (转载)Linux 套接字编程中的 5 个隐患
    一个Sqrt函数引发的血案
    二叉搜索树BinarySearchTree(C实现)
    vector,list.queue,array.....
    boost::Circular Buffer
    boost::operators
    Disjoint Sets
  • 原文地址:https://www.cnblogs.com/zhang1997/p/8555262.html
Copyright © 2011-2022 走看看