public void RegSubmit(Object obj,EventArgs e)
 {
  string str="";
  str+="'"+userID.Text+"',";   //response to product id
  str+="'"+userName.Text+"',";
  str+="'"+password.Text+"',";
  str+="'"+IDcard.Text+"',";
  str+="'"+birth_year.Text+"-";
  str+=birth_month.SelectedItem.Value+"-";
  str+=birth_day.Text +"',";
 
  if(sex1.Checked==true)
  str+=1;
  if(sex2.Checked==true)
  str+=0;
  
  
  str+=",'"+province.SelectedItem.Text+"',";
  str+="'"+address.Text+"',";
  str+="'"+Handphone.Text+"',";
  str+="'"+Telephone.Text+"',";
  str+="'"+Email.Text+"',";
 
  str+="'"+yourEducation.SelectedItem.Text+"',";
  str+="'"+yourTrade.SelectedItem.Text+"',";
  str+="'"+yourJob.SelectedItem.Text+"',";
  
 
 if(Page.IsValid==true)
 {
testLab.Text=str;  
Add(str);
  }
  
  else
  {
  
  testLab.Text="验证未通过";
 
  }
//  Response.Redirect("Register2.aspx");
  
 }
 public void jobselect(Object obj,EventArgs e)
 {
  // Response.Write(obj.SelectedIndex.ToString());
 }
  
 public void Add(String param)
 {
    String sql=null ;
   sql="insert into customerinfo(ProductID,userName,[password],idcard,birthday,sex,province,address,handphone,telephone,email,education,trade,job,registertime) values("+param+"getdate())";
 
  SqlConnection conn=new SqlConnection("server=localhost;uid=sa;pwd=mos;database=customers;Trusted_Connection='no';");
SqlCommand comm=new SqlCommand(sql,conn);
try
{
conn.Open();
comm.ExecuteNonQuery();
}
catch(Exception e)
{
//Response.Write("Error  ins"+e.ToString()); 
conn.Close();
Response.Write("Error Database="+e.ToString());
}
finally
{
if(conn.State==ConnectionState.Open)
conn.Close();
}  }

解决方案 »

  1.   

    这是测试结果:'sdfsadf','dsf','1111','422425197902100416','1979-2-10',0,'北京','dfg','12345678901','dfg','[email protected]','请选择  ',' 请选择','请选择  ',
      

  2.   

    你一共用了4个dropdownlist?第一个关于生日是正确的?
    其他三个都是错误的?
    AutoPostBack是false?你把它改称true。
      

  3.   

    你说的对, 第一个关于生日是正确的  !但是其他 3个是错误的 ,我改了 Autopostback 也没有用我昨天写代码的时候也发现了 ,这个问题,好象 value 里面不能有中文,
    所以我才用      SelectedItem.Text   ,但是下面的例子很成功啊 ?为什么?
    <%@page language="c#" %><script language="c#" runat="server">public void ss(Object obj,EventArgs e)
    {
      Label1.Text=dp1.SelectedItem.Value;
    }
    </script>
    <form runat=server method=post > <asp:Label id="Label1" runat="server"/><asp:dropdownlist   autopostback=true  OnSelectedIndexChanged="ss" id=dp1 runat=server >
    <asp:listitem value="测试0"> 1000</asp:listitem>
    <asp:listitem value="测试1">2000</asp:listitem>
    </asp:dropdownlist >
     
    </form>
      

  4.   

    我试了一下在AutoPostBack是true的情况下,是正确的。
    对不起,找不出你的问题,你在自己检查一下吧
      

  5.   

    可以在每个DropDownList中使用OnSelectedIndexChanged;同时设置autopostback=true 如OnSelectedIndexChanged="ss"public void ss(Object obj,EventArgs e)
    {
     d= (DropDownList)e.Sender;
    if(d==province)
    {
      str=province.SelectedItem.Text;
    }
    else if(d==yourEducation)
    {
      str=yourEducation.SelectedItem.Text;
    }
    ......
    }
    you try::
      

  6.   

    首先感谢你的回答 ! supnet (c )
    我现在发现问题的是这样的,(我在代码中改为英文数字都可以)
     <asp:ListItem  Value="也不能用中文" >不支持中文</asp:ListItem>如果是<asp:ListItem Value="" > 请选择</asp:ListItem>
    使用  SelectedItem.Text 那么就等于请选择,但是我发的第二例子 个却能正却显示,为什么这么奇怪
    <%@page language="c#" %>
    <script language="c#" runat="server">public void ss(Object obj,EventArgs e)
    {
      Label1.Text=dp1.SelectedItem.Value;
    }
    </script>
    <form runat=server method=post >
     <asp:Label id="Label1" runat="server"/><asp:dropdownlist   autopostback=true  OnSelectedIndexChanged="ss" id=dp1 runat=server >
    <asp:listitem value="测试0"> 1000</asp:listitem>
    <asp:listitem value="测试1">2000</asp:listitem>
    </asp:dropdownlist >
    </form>
      

  7.   

    说明: 头上成功的代码是用记事本写的,没有在开发环境 c# 中写, 而不支持中文的是在开发环境中写的。难道说 开发 环境中有 bug  ? 我的开发环境中是 
    <%@ Page language="c#" Codebehind="Register.aspx.cs" AutoEventWireup="false" Inherits="Customer.WebForm1" codePage="936"%>
    BG2312
      

  8.   

    你可以不用ASP。NET的控件,将代码改为<select >,那么只要在BUTTONCLICK 事件中向数据库写就可以拉
      

  9.   

    是的 ,其实这个 选择完全可以不用 ASP.net  Web Server Controls ,但是我是初学,被这个鬼东东搞晕了 ,我又没有见过  微软官方说 不准在 value 用 中文,只有吃一堑长一智罗,大家还有什么象这样的教训写出来嘛 ,我下班前结帖。