前台代码如下:<body >
    <form id="form1" runat="server">
        <div style="background-color: #99ffff">
            &nbsp;<table style="border: 1  620px; height: 416px; display: inline; visibility: visible;
                text-align: center; left: 0px; position: relative; top: 11px; border-right: #99ffff thin solid;
                border-top: #99ffff thin solid; vertical-align: middle; border-left: #99ffff thin solid;
                color: #0000ff; border-bottom: #99ffff thin solid; font-family: 新宋体; background-color: #ffcc66;
                padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px;
                clear: both; table-layout: fixed; float: none; border-collapse: collapse; width: 611px;
                cursor: hand; text-indent: 0pt;">
                <tr>
                    <td>
                        <asp:CheckBoxList runat="server" ID="ch" RepeatColumns="5" AutoPostBack="True" CellPadding="2"
                            OnSelectedIndexChanged="ch_SelectedIndexChanged" BorderColor="#999999" DataMember="vcc"
                            DataTextField="CANDIDATES" DataValueField="姓名" RepeatDirection="Horizontal" BackColor="#F0F0E8"  CellSpacing="0" DataSourceID="SqlDataSource1" >
                        </asp:CheckBoxList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                            ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand='SELECT "CANDIDATES" FROM "VCC"'>
                        </asp:SqlDataSource>
                    </td>
                </tr>
            </table>
        </div>
        <div style="background-attachment: fixed; background-repeat: repeat; background-color: #99ffff">
            <br />
            <table style="width: 604px; height: 1px; table-layout: fixed; padding-right: 0px;
                display: block; padding-left: 0px; border-left-color: #ffffcc; background-image: none;
                visibility: visible; border-bottom-color: #ffffcc; padding-bottom: 0px; margin: 0px;
                vertical-align: middle; overflow: auto; cursor: hand; color: black; border-top-style: ridge;
                border-top-color: #ffffcc; text-indent: 2pt; padding-top: 0px; font-style: normal;
                border-right-style: ridge; border-left-style: ridge; position: static; border-collapse: separate;
                background-color: #ffcc33; text-align: center; border-right-color: #ffffcc; border-bottom-style: ridge;"
                id="TABLE1" onclick="return TABLE1_onclick()">
                <tr>
                    <td colspan="2">
                        <span style="font-size: 14pt">请输入信息:</span></td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align: left; height: 29px;">
                        真实姓名:<asp:TextBox ID="aa" runat="server" Style="left: 6px; position: relative; top: -2px"
                            Width="156px"></asp:TextBox>&nbsp; 身份证号:<asp:TextBox ID="TextBox2" runat="server"
                                Style="position: relative; left: 13px; top: 0px;" Width="161px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="text-align: left; width: 254px; height: 27px;">
                        <asp:TextBox ID="GUID" runat="server" Width="0px" Visible="False"></asp:TextBox>
                        <asp:Button ID="add" runat="server" Style="position: relative; left: 42px; top: 2px;"
                            Text="提交选票" BackColor="#FF8000" BorderColor="Red" Font-Bold="True" Height="29px"
                            Width="93px" OnClick="add_Click" />
                        <asp:Button ID="Reset" runat="server" Style="left: 287px; position: relative; top: -1px"
                            Text="重新投票" BackColor="#FF8000" BorderColor="Red" Font-Bold="True" Height="29px"
                            Width="86px" OnClick="Reset_Click" /></td>
                </tr>
            </table>
        </div>
    </form>
</body>
做的是投票网站,提交选票,重新投票两个按钮如何把前台显示数据填到数据库表vcc中数据库表vcc:
REALNAME NVARCHAR2(20) Y 投票者真实姓名
IDNUMBER VARCHAR2(60) Y 投票者身份证号
IPADDRESS VARCHAR2(60) Y 投票者ip地址
VOTES VARCHAR2(30) Y 投票者投票数
CANDIDATES NVARCHAR2(20) N 竞选者姓名
NUMBEROFVOTES VARCHAR2(60) Y 竞选者得票数
后台代码是:public partial class _Default2 : System.Web.UI.Page
{
    private DataView dv = null;
    string sql = "";
    private string strconnection = "";
    private OracleConnection myconnection = null;
    protected void Page_Load(object sender, EventArgs e)
    {        strconnection = "Data Source=orcl9i;Persist Security Info=True;User ID=scmis;Password=lgmis;";
        myconnection = new OracleConnection(strconnection);
        if (!IsPostBack)
        {
            InitDrop();
            Init();
        }
    }
    private void InitDrop()
    {
        DataTable dt = ExecuteDatasetFromSql("select * from vcc").Tables[0];
        CheckBoxList.DataSource = dt; //绑定数据源
        CheckBoxList.DataTextField = "CANDIDATES"; //文本内容字段
        CheckBoxList.DataValueField = "姓名"; //值字段               [color=#0000FF]这一段checkboxlist绑定数据库表 投票人姓名,对不?
        CheckBoxList.DataBind();
        foreach (ListItem item in CheckBoxList.Items)[/color]        
    item.Selected = true;
                                
    }    private DataView GetDv(string ls_str)
    {
        DataSet ds = ExecuteDatasetFromSql(ls_str);
        dv = ds.Tables[0].DefaultView;
        return dv;
    }
    private void Init()
    {
        DataSet ds = ExecuteDatasetFromSql("select * from vcc  where guid='" + guid + "'");
        if (ds.Tables[0].Rows.Count != 0)
        {
            AA.Text = ds.Tables[0].Rows[0]["AA"].ToString();
            BB.Text = ds.Tables[0].Rows[0]["BB"].ToString();
        }
    }
    public int ExecuteNonQueryFromSql(string sqlcmd)
    {
        int num = -1;
        OracleCommand ocmd = new OracleCommand(sqlcmd, myconnection);
        try
        {
            myconnection.Open();
            num = ocmd.ExecuteNonQuery();        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            myconnection.Close();
        }
        return num;
    }
    public DataSet ExecuteDatasetFromSql(string sqlcmd)
    {
        DataSet ds = new DataSet();
        try
        {
            myconnection.Open();
            OracleDataAdapter da = new OracleDataAdapter(sqlcmd, myconnection);
            OracleCommandBuilder orbc = new OracleCommandBuilder(da);
            da.Fill(ds);
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            myconnection.Close();
        }
        return ds;
    }    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
        //
        // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
        //
        InitializeComponent();
        base.OnInit(e);
    }    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    #endregion
    protected void add_Click(object sender, EventArgs e)
    {
      
               //投票数<=10 提示请重新投票,否则投票成功。    }
    protected void Reset_Click(object sender, EventArgs e)
    {
        //提示重新投票功能。
    }}private void InitDrop 那一段对不?还有两个按钮如何实现:前台无投票人ip,投票人投票数,竞选者得票数?

解决方案 »

  1.   

     主要问题是checkboxlist如何绑定数据库,在前台显示出来及投票后把一系列投票和得票保存在数据库表中?   是投票系统
      

  2.   

    没明白  不明白你的CheckBoxList和数据库里的字段怎么对应   
      

  3.   

    绑定数据库我已经搞定了,现在问题是对checkboxlist如何判断其内容不为空,将投票的结果保存到数据库表中
      

  4.   

    [size=10px]请高手指教!!![/size]
      

  5.   

    通过ch.Items.Count是否为0来判断checkboxlist是否为空呀。然后对于点击投票,也就是会调用你的ch_SelectedIndexChanged方法,在这里面对ch的items进行遍历 foreach (ListItem li in ch.Items) 
     {
         if (li.Selected) 
         {
             li.Text...
         }
     }就可以投票人选中的竞选者信息了呀。然后加入数据库就简单了
      

  6.   

     protected void add_Click(object sender, EventArgs e) 
        { 
          
          这里具体怎么写? 要显示投票人的投票数,和竞选者得票数。       //投票数 <=10 提示请重新投票,否则投票成功。     } 
            
    高手们,你们说具体点,行吗?请详细回答下!!