自定义类取session的值
HttpContext.Current.Session["a"]="hello";
.CS 文件里改变文字颜色
"<font Color='red'>(" + GetNameById(sql) + ")</font>"
asp.net 弹出对话框
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "str", "<script>alert(\"添加成功!\");window.location.href='EnvironmentMng.aspx'</script>");
asp.net后台获取html控件值
<input id="yBirthDay" type="text" name="yBirthDay" />
Label1.Text = Request.Form["yBirthDay"].ToString();
sql2000 :
<add name="ConnectionString" connectionString="server=192.168.1.9;uid=sa;pwd=Mn06IISSVR6;database=tyyl_sqlserver" providerName="System.Data.SqlClient"/>
sql2005 sqlexpress:
<add name="hospitalConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=hospital;Trusted_Connection=yes" providerName="System.Data.SqlClient"/>
asp.net include 页面:
<%--#include virtual = "/bin/comm_site/inc_page_end.aspx" --%>
asp.net datagrid 行变色
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand';c=this.style.backgroundColor;this.style.backgroundColor='#E7EFFC'");
e.Row.Attributes.Add("onmouseout", "this.style.cursor='';this.style.backgroundColor=c");
}
}
asp.net动态创建table column
public void SearchReportByVid()
{
DataTable dt = manager.SearchReportByVid(vid+flag).Tables[0];
DataTable dtt = new DataTable("dttt");
DataRow newRow = null;
if (dt.Rows.Count != 0)
{
DataColumn dc = new DataColumn();
dc = dtt.Columns.Add("item_name", Type.GetType("System.String"));
for (int i =0; i < dt.Rows.Count; i++)
{
if (i < dt.Rows.Count - 1)
{
if (dt.Rows[i]["item_name"].ToString().Trim() != dt.Rows[i + 1]["item_name"].ToString().Trim())
{
newRow = dtt.NewRow();
newRow["item_name"] = dt.Rows[i]["item_name"].ToString();
dtt.Rows.Add(newRow);
}
}
else {
newRow = dtt.NewRow();
newRow["item_name"] = dt.Rows[i]["item_name"].ToString();
dtt.Rows.Add(newRow);
}
}
}
}
绑定下拉列表
public void InitDataAll()
{
this.yPlace.Items.Clear();
DataSet ds = manager.GetCheckHelthPlaceAll();
this.yPlace.DataSource = ds.Tables[0];
this.yPlace.DataTextField = "dtext";
this.yPlace.DataValueField = "arid";
this.yPlace.DataBind();
}
asp.net 上传图片
if (file.HasFile)
{
string fileContentType = file.PostedFile.ContentType;
if (fileContentType == "image/gif" || fileContentType == "image/pjpeg")
{
Random number = new Random();
string filename = DateTime.Now.ToString("yyyyMmddhhmmssfff") + "_" + number.Next(10000, 99999).ToString() + "_" + file.PostedFile.ContentLength + System.IO.Path.GetExtension(file.PostedFile.FileName);
string filenameGUID = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName);
file.SaveAs(Server.MapPath("~/pic/") + filenameGUID);
pic.Text = "pic/" + filenameGUID;
img.Visible = true;
img.ImageUrl = "pic/" + filenameGUID;
//下面不是自动命名上传图片,直接上传原文件的名字图片
//string strDir = file.FileName;
//string strPath = Server.MapPath("~/pic/") + strDir;
//file.SaveAs(strPath);
//pic.Text = "pic/" + strDir;
//img.Visible = true;
//img.ImageUrl = "pic/" + strDir;
}
else
{
infro.Visible = true;
infro.Text = "提示:文件类型不符,只能上传JPG,GIF图片!";
}
}
查询分析器修改SQL登录密码:
EXEC sp_password NULL, '你的新密码', 'sa'
asp.net 日期格式绑定
Text='<%# DataBinder.Eval(Container, "DataItem.yyrq2","{0:yyyy-MM-dd}").ToString() %>'
<asp:TemplateField HeaderText="发布日期">
<ItemTemplate>
<%# Eval("dt","{0:d}")%>
</ItemTemplate>
</asp:TemplateField>
div+css 以IE7浏览器来渲染,兼容IE8
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
div+css 以IE5浏览器来渲染,兼容IE5及以浏览器下版本
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">