| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 700 人关注过本帖
标题:有个急问题,请教大家,请帮忙解决,谢谢了.
只看楼主 加入收藏
Cristinas
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-8-16
收藏
 问题点数:0 回复次数:1 
有个急问题,请教大家,请帮忙解决,谢谢了.

我想测试一个可以输入的文本框的字数,如果输入>70个字符的,就显示'发送内容过长,请重新输入!',如果<70,则显示'输入成功!'. 可我不知道该怎么显示示'发送内容过长,请重新输入!', private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here SqlConnection myconnect = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]); //if(!IsPostBack) //{ Label1.Text = Session["quanxian"].ToString().Trim(); name.Text = Session["username"].ToString(); if(!IsPostBack) { SqlDataAdapter sqlDataAdapterbm = new SqlDataAdapter("select teamname from userteam where userid = @userid",myconnect); DataSet dataSetbm = new DataSet(); sqlDataAdapterbm.SelectCommand.Parameters.Add("@userid", SqlDbType.Char, 10).Value = name.Text.Trim(); sqlDataAdapterbm.Fill(dataSetbm,"faults"); DropDownList1.DataSource = dataSetbm.Tables["faults"].DefaultView; DropDownList1.DataTextField = "teamname"; DropDownList1.DataBind(); } if(Label1.Text.Trim()=="1") { Control ctl = LoadControl("../control/Headersite2.ascx");

Controls.Add(ctl); } if(Label1.Text.Trim()=="4") { Control ctl = LoadControl("../control/Headersite2.ascx");

Controls.Add(ctl); } if(Label1.Text.Trim()=="2") { Control ctl = LoadControl("../control/Headersite1.ascx");

Controls.Add(ctl); } //} }

#region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.sqlConnection1 = new System.Data.SqlClient.SqlConnection(); this.sqlConnection2 = new System.Data.SqlClient.SqlConnection(); this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Button2.Click += new System.EventHandler(this.Button2_Click); // // sqlConnection1 // this.sqlConnection1.ConnectionString = "data source=172.18.58.10;initial catalog=message;password=message;persist securit" + "y info=True;user id=message;workstation id=GAOLIN;packet size=4096"; // // sqlConnection2 // this.sqlConnection2.ConnectionString = "data source=172.18.58.10;initial catalog=rsxz;password=message;persist security i" + "nfo=True;user id=message;workstation id=GAOLIN;packet size=4096"; this.Load += new System.EventHandler(this.Page_Load);

} #endregion

private void Button1_Click(object sender, System.EventArgs e) { if(TextBox2.Text.Trim().Length>70) { Response.Write ("<script language='javascript'>alert('发送内容过长,请重新输入!')</script>"); } if(TextBox2.Text.Trim().Length<=70) { SqlConnection myconnect = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]); string temp1 = ""; string str = TextBox1.Text.Trim(); string [] strarr = str.Split(',',',','.','。',' '); //string mobileString = "13\\d{9}";

for(int i=0;i<strarr.Length;i++) {//a //strarr[i]; if((strarr[i].Length!=11) && (strarr[i].Trim()!="")) {//b SqlDataAdapter sqlDataAdapterbm = new SqlDataAdapter("select teamid from userteam where teamname = @teamname",myconnect); DataSet dataSetbm = new DataSet(); sqlDataAdapterbm.SelectCommand.Parameters.Add("@teamname", SqlDbType.Char, 30).Value = strarr[i].Trim(); sqlDataAdapterbm.Fill(dataSetbm,"faults"); if (dataSetbm.Tables["faults"].Rows.Count>0) { temp1 = dataSetbm.Tables["faults"].Rows[0]["teamid"].ToString().Trim(); } if (dataSetbm.Tables["faults"].Rows.Count<1) { temp1 = ""; } if(temp1 != "") {//c SqlDataAdapter sqlDataAdapterbm1 = new SqlDataAdapter("select yonghu,telph from purview1 where teamid = @teamid",myconnect); DataSet dataSetbm1 = new DataSet(); sqlDataAdapterbm1.SelectCommand.Parameters.Add("@teamid", SqlDbType.Char, 4).Value = temp1; sqlDataAdapterbm1.Fill(dataSetbm1,"faults1"); DataTable dt=dataSetbm1.Tables[0]; foreach(DataRow dr in dt.Rows) {//d //string gongsidaima=dr[0].ToString().Trim(); string yonghu=dr[0].ToString().Trim(); string shouji=dr[1].ToString().Trim(); if(yonghu!="") {//e SqlDataAdapter sqlDataAdapterbm2 = new SqlDataAdapter("select * from mobile_info where userid = @userid",sqlConnection2); DataSet dataSetbm2 = new DataSet(); sqlDataAdapterbm2.SelectCommand.Parameters.Add("@userid", SqlDbType.Char, 20).Value = yonghu; //sqlDataAdapterbm2.SelectCommand.Parameters.Add("@workno", SqlDbType.Char, 5).Value = gonghao; sqlDataAdapterbm2.Fill(dataSetbm2,"faults2");

string temp2; temp2 = dataSetbm2.Tables["faults2"].Rows[0]["mobile"].ToString().Trim(); string strinsert; strinsert = "insert into send(smid,userid,scontent,flag,destaddress)values('62257496',@userid,@scontent,'0',@destaddress)"; SqlCommand cmdinsert = new SqlCommand(strinsert,sqlConnection1); cmdinsert.Parameters.Add("@userid",name.Text.Trim()); cmdinsert.Parameters.Add("@scontent",TextBox2.Text.Trim()); cmdinsert.Parameters.Add("@destaddress",temp2); cmdinsert.Connection.Open(); cmdinsert.ExecuteNonQuery(); cmdinsert.Connection.Close(); }//e if(yonghu=="") {//f //string shouji=dr[2].ToString().Trim(); string strinsert8; strinsert8 = "insert into send(smid,userid,scontent,flag,destaddress)values('62257496',@userid,@scontent,'0',@destaddress)"; SqlCommand cmdinsert8 = new SqlCommand(strinsert8,sqlConnection1); cmdinsert8.Parameters.Add("@userid",name.Text.Trim()); cmdinsert8.Parameters.Add("@scontent",TextBox2.Text.Trim()); cmdinsert8.Parameters.Add("@destaddress",shouji); cmdinsert8.Connection.Open(); cmdinsert8.ExecuteNonQuery(); cmdinsert8.Connection.Close();

}//f }//d }//c

}//b if(strarr[i].Length==11) { if(strarr[i].Substring(0,2)!="13") {

} if(strarr[i].Substring(0,2)=="13") { string strinsert; strinsert = "insert into send(smid,scontent,flag,destaddress)values('62257496',@scontent,'0',@destaddress)"; SqlCommand cmdinsert = new SqlCommand(strinsert,sqlConnection1); cmdinsert.Parameters.Add("@scontent",TextBox2.Text.Trim()); cmdinsert.Parameters.Add("@destaddress",strarr[i].Trim()); cmdinsert.Connection.Open(); cmdinsert.ExecuteNonQuery(); cmdinsert.Connection.Close(); } } }//a TextBox1.Text = ""; TextBox2.Text = ""; Response.Write ("<script language='javascript'>alert('输入成功!')</script>");

} } private void Button2_Click(object sender, System.EventArgs e) { if(TextBox1.Text.Trim() != "") { TextBox1.Text = TextBox1.Text + ',' + DropDownList1.SelectedItem.Text.Trim(); } if(TextBox1.Text.Trim() == "") { TextBox1.Text = DropDownList1.SelectedItem.Text.Trim();

} } } }

搜索更多相关主题的帖子: void 测试 private 文本框 
2005-08-16 11:18
Cristinas
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-8-16
收藏
得分:0 
怎么没人帮我啊,谢谢了
2005-08-16 11:28
快速回复:有个急问题,请教大家,请帮忙解决,谢谢了.
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017695 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved