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();
} }
{
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();
} }
其他三个都是错误的?
AutoPostBack是false?你把它改称true。
所以我才用 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>
对不起,找不出你的问题,你在自己检查一下吧
{
d= (DropDownList)e.Sender;
if(d==province)
{
str=province.SelectedItem.Text;
}
else if(d==yourEducation)
{
str=yourEducation.SelectedItem.Text;
}
......
}
you try::
我现在发现问题的是这样的,(我在代码中改为英文数字都可以)
<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>
<%@ Page language="c#" Codebehind="Register.aspx.cs" AutoEventWireup="false" Inherits="Customer.WebForm1" codePage="936"%>
BG2312