📄 updatemsg2.aspx.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.ComponentModel;
using System.Web.SessionState;
using System.Globalization;
public partial class UpdateMsg : System.Web.UI.Page, ICallbackEventHandler ///小心
{
public string strcity;
public string strpro;
public void SetTime()
{
int i;
ArrayList mounth = new ArrayList();
for (i = 1; i <= 12; i++)
mounth.Add(i);
this.Mounth.DataSource = mounth;
this.Mounth.DataBind();
//以上初始化月
int j;
ArrayList year = new ArrayList();
for (j = 1900; j <= 2020; j++)
year.Add(j);
this.Year.DataSource = year;
this.Year.DataBind();
//以上初始化年
// this.Mounth.AutoPostBack = true;
// this.Year.AutoPostBack = true;
}
public void daynum(string num)
{
int i;
ArrayList day = new ArrayList();
for (i = 1; i <= Convert.ToInt16(num); i++)
day.Add(i);
this.Day.DataSource = day;
this.Day.DataBind();
}
public void day(string mth, int year)
{
switch (mth)
{
case "1":
case "3":
case "5":
case "7":
case "8":
case "10":
case "12":
daynum("31");
break;
case "2":
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
daynum("29");
else
daynum("28");
break;
default:
daynum("30");
break;
}
}
private void ImgList()
{
if (!IsPostBack)
{
int j;
ArrayList ListImg = new ArrayList();
for (j = 1; j <= 100; j++)
{
String temp;//image9.gif
temp = "image" + j + ".gif";
ListImg.Add(temp);
}
this.Figure.DataSource = ListImg;
this.Figure.DataBind();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserID"] == null)
Session["UserID"] = "04157008 ";
string cmd;
//////if ( other != "")
//////{
// cmd = " SELECT [UserID], [Email], [Tele], [MobilePh], [PicName], [QQ], [StudentID] FROM [UserInfo] where " + field + "='" + condition + "' or" + other + "='" + condition + "'"; ;//设置SQL命令
//}
//else
//{
cmd = "SELECT StudentInfo.Name, UserInfo.Sex, UserInfo.Tele, UserInfo.MobilePh, UserInfo.QQ, UserInfo.Email, UserInfo.PicName FROM StudentInfo INNER JOIN UserInfo ON StudentInfo.StudentID = UserInfo.StudentID where UserID='" + Session["UserID"].ToString() + "'";
;//设置SQL命令
//}
this.SqlDataSource1.SelectCommand = cmd;
this.SqlDataSource1.DataBind(); //将SqlDataSource重新绑定
this.DataList1.DataBind();
//SELECT StudentInfo.Name, UserInfo.Sex, UserInfo.Tele, UserInfo.MobilePh, UserInfo.QQ, UserInfo.Email FROM StudentInfo INNER JOIN UserInfo ON StudentInfo.StudentID = UserInfo.StudentID
////接收参数
string sortid = this.Request.QueryString["sortid"];
string sType = this.Request.QueryString["sType"];
strcity = Request.Form["hideCity"];
strpro = Request.Form["Hiddenpro"];
// this.City.Value = strcity;
//判断参数是否为空(注意:空有两种形式,一种为null,一种为空)
if (sortid + "a" != "a")
{
//如果有传递上述参数,则表示联动操作开始
this.xmlBind(sortid, sType);
}
// this.Country.Text = "qrwrwer";
// this.City. = "sdjfl";
if (!this.IsPostBack)
{
// this.xmlBind("110000", "2");
this.DownBind1();
this.DownBind2();
// this.DownBind3();
this.SetTime();
// day(this.Mounth.SelectedValue, Convert.ToInt16(this.Year.SelectedValue));
ImgList();
}
//if (!IsPostBack)
//{
// // this.Binder();
// this.SetCountry();
this.Mounth.Attributes.Add("onchange", "CallMounthSel(this,Year)");
this.Year.Attributes.Add("onchange", "CallYearSel(Mounth,this)");
this.Figure.Attributes.Add("onchange", "ImageSel(Figure)");
Databind();
}
private string serverReturn;
public string GetCallbackResult()
{
//为便于查看加载效果,添加延时
// System.Threading.Thread.Sleep(2000);
string[] parts = serverReturn.Split('|');
//根据传递的方法名进行调用,并传递相应的参数,目前只支持一个参数
return (string)GetType().GetMethod(parts[0]).Invoke(this, new object[] { parts[1] });
// return ServerMethod2(serverReturn);
}
public void RaiseCallbackEvent(string eventArgument)
{
serverReturn = eventArgument;
//可直接返加 return eventArgument;
}
// 根据从客户端传来的值,对内容进行更新,并将更新后返回
public string MounthSel(string arg)
{
string[] parts = arg.Split('*');
day(parts[0], Convert.ToInt16(parts[1]));
return RenderControl(Day);
}
public string YearSel(string arg)
{
// DropDownList1.SelectedValue = arg;
//.DataBind();//Convert.ToInt16(num)
string[] parts = arg.Split('*');
day(parts[0], Convert.ToInt16(parts[1]));
return RenderControl(Day);
}
public string SelPic(string arg)
{
//string temp = this.Figure.SelectedItem.Text;
// 头像列表 <img id="SelPic" alt="" src="HeadPic/image28.gif" style="width: 46px; height: 43px" />
this.PicLink.Text = " 头像列表 <img id=\"SelPic\" alt=\"\" src=\"HeadPic/" + arg + "\" style=\"width: 46px; height: 43px ;border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none;\" />";
return RenderControl(PicLink);
}
private string RenderControl(Control control)
{
StringWriter writer1 = new StringWriter(CultureInfo.InvariantCulture);
HtmlTextWriter writer2 = new HtmlTextWriter(writer1);
control.RenderControl(writer2);
writer2.Flush();
writer2.Close();
return writer1.ToString();
}
private void xmlBind(string sortid, string sType)
{
string mystr = "";
string sql = "";
if (sType == "1")
{
sql = "select provinceID as id,province as sname from province where father = " + sortid;
}
else
{
sql = "select cityID as id,city as sname from city where father = " + sortid;
//string sValue = this.Province.SelectedValue;
////第一个下拉框有值才开始绑定第二个下拉框
//if (sValue != "")
//{
//默认显示分类号为1的所有子类
// string cmd = "select cityID,city from city where father = " + sortid;
// DataTable tab = this.Get_Dt(cmd);
// //绑牢控件
// this.City.DataSource = tab;
// this.City.DataSource = tab;
// this.City.DataValueField = "cityID";
// this.City.DataTextField = "city";
// this.City.DataBind();
////}
}
DataTable mytab = this.Get_Dt(sql);
//将取到的值形成: ID|名称,ID|名称...这样的形式
if (mytab.Rows.Count != 0)
{
for (int i = 0; i < mytab.Rows.Count; i++)
{
mystr += "," + mytab.Rows[i]["id"].ToString() + "|" + mytab.Rows[i]["sname"].ToString();
}
mystr = mystr.Substring(1);
}
//输出页面
this.Response.Write(mystr);
this.Response.End();
}
private DataTable Get_Dt(string sql)
{
//数据库连接串,本数据库为Sql数据库,当前在本目录的根目录下
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
conn.Open();
SqlDataAdapter myAdp = new SqlDataAdapter(sql, conn);
DataTable myDt = new DataTable();
//填充数据
myAdp.Fill(myDt);
//返回数据集
conn.Close();
return (myDt);
}
/// <summary>
/// 绑定第一个下拉框
/// </summary>
private void DownBind1()
{
//显示所有的主分类
string sql = "select CountryID,CountryName from Country ";
DataTable mytab = this.Get_Dt(sql);
//绑定第一个下拉框
this.Country.DataSource = mytab;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -