用RadioButtonList来设置性别,
那个代码应该怎么样写
int sex=Convert.ToInt32("RadioButtonList1.SelectedItem.Value");
但浏览的时候他出出错了
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace Web96
{
/// <summary>
/// zhuce 的摘要说明。
/// </summary>
public class zhuce : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtzhanghao;
protected System.Web.UI.WebControls.TextBox txtpass;
protected System.Web.UI.WebControls.TextBox txtrepass;
protected System.Web.UI.WebControls.TextBox txtmail;
protected System.Web.UI.WebControls.TextBox txtwen;
protected System.Web.UI.WebControls.TextBox txtda;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
protected System.Web.UI.WebControls.DropDownList DropDownList3;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.CompareValidator CompareValidator2;
protected System.Web.UI.WebControls.DropDownList DropDownList4;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void LinkButton1_Click(object sender, System.EventArgs e)
{
string users=txtzhanghao.Text;
string pass=txtpass.Text;
string mail=txtmail.Text+DropDownList4.SelectedItem.Value;
string wenti=txtwen.Text;
string huida=txtda.Text;
string birth=DropDownList1.SelectedItem.Value+"-"+DropDownList2.SelectedItem.Value+"-"+DropDownList3.SelectedItem.Value;
int sex=Convert.ToInt32("RadioButtonList1.SelectedItem.Value");
string sql="insert into zhuce(users,pass,sex,birth,mail,wenti,huida) values('"+users+"','"+pass+"','"+sex+"','"+birth+"','"+mail+"','"+wenti+"','"+huida+"')";
SqlConnection con=new SqlConnection("server=.;database=model;uid=sa;pwd=");
con.Open();
SqlCommand cmd=new SqlCommand(sql,con);
int i=cmd.ExecuteNonQuery();
if(i>0)
Response.Redirect("yes.aspx");
else
Response.Redirect("no.aspx");
}
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("");
}
}
}
还是不可以啊
我开始就是用
int sex=Convert.ToInt32(RadioButtonList1.SelectedItem.Value);
试了的
他说是
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.FormatException: 输入字符串的格式不正确。
源错误:
行 72: string huida=txtda.Text;
行 73: string birth=DropDownList1.SelectedItem.Value+"-"+DropDownList2.SelectedItem.Value+"-"+DropDownList3.SelectedItem.Value;
行 74: int sex=Convert.ToInt32(RadioButtonList1.SelectedItem.Value);
行 75: string sql="insert into zhuce(users,pass,sex,birth,mail,wenti,huida) values('"+users+"','"+pass+"','"+sex+"','"+birth+"','"+mail+"','"+wenti+"','"+huida+"')";
行 76: SqlConnection con=new SqlConnection("server=.;database=model;uid=sa;pwd=");