日本語900句 ローデイング...
日语900句 加载中...
小问题集
作者:小轩 日期:2008-07-24
SQL 全集
作者:小轩 日期:2008-06-02
人类本性
作者:小轩 日期:2007-11-01
自动跳转
作者:小轩 日期:2010-02-02
无缝向上滚动代码
作者:小轩 日期:2010-01-06
程序代码<html>
<HEAD>
<TITLE>自动向上滚动的文本,鼠标放上去就停止</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
</HEAD>
<body>
<div id="demo" style="overflow:hidden;height:100%;width:100%; border:1px solid #dde5bc;">
<div id="demo1">
<!------------------------------------------------------------------------------------------------>
要滚动显示的内容代码
<!------------------------------------------------------------------------------------------------->
</div>
<div id="demo2"></div>
</div>
<script>
查询参数化
作者:小轩 日期:2009-09-01
--Web.Config 配置
<appSettings>
<add key="MessageBoardConn" value="server=IP地址;uid=sa;pwd=;database=MessageBoard" />
</appSettings>
---页面绑定代码:(查询参数化)
String DBConnStr;
DataSet MyDataSet=new DataSet();
TextBox1.Text ="'2";
System.Data.SqlClient.SqlDataAdapter DataAdapter=new System.Data.SqlClient.SqlDataAdapter();
DBConnStr=System.Configuration.ConfigurationSettings.AppSettings["MessageBoardConn"];
System.Data.SqlClient.SqlConnection myConnection = new System.Data.SqlClient.SqlConnection(DBConnStr);
if (myConnection.State!=ConnectionState.Open)
{
myConnection.Open();
}
System.Data.SqlClient.SqlCommand myCommand = new System.Data.SqlClient.SqlCommand("select * from TB_B_Zixun where Oid=@id",myConnection);
myCommand.Parameters.Add("@id",SqlDbType.Int );
myCommand.Parameters["@id"].Value =2 ; //参数化赋值
<appSettings>
<add key="MessageBoardConn" value="server=IP地址;uid=sa;pwd=;database=MessageBoard" />
</appSettings>
---页面绑定代码:(查询参数化)
String DBConnStr;
DataSet MyDataSet=new DataSet();
TextBox1.Text ="'2";
System.Data.SqlClient.SqlDataAdapter DataAdapter=new System.Data.SqlClient.SqlDataAdapter();
DBConnStr=System.Configuration.ConfigurationSettings.AppSettings["MessageBoardConn"];
System.Data.SqlClient.SqlConnection myConnection = new System.Data.SqlClient.SqlConnection(DBConnStr);
if (myConnection.State!=ConnectionState.Open)
{
myConnection.Open();
}
System.Data.SqlClient.SqlCommand myCommand = new System.Data.SqlClient.SqlCommand("select * from TB_B_Zixun where Oid=@id",myConnection);
myCommand.Parameters.Add("@id",SqlDbType.Int );
myCommand.Parameters["@id"].Value =2 ; //参数化赋值
如何把数据放到web不能访问的文件夹中并给用户下载?[转]
作者:小轩 日期:2009-08-28
在应用中我们可能遇到这样的情况,我们需要临时生成一个数据文件给用户下载,但是每次下载都要判断,也就是说,用户并不能得到这个下载的url不断下载文件,下面是实现方法。文件保存为csv格式,方便数据导入导出,基本原理就是用流写入文件然后用Response.WriteFile把流发送到客户端。
表的结构同此文:http://blog.csdn.net/lovecherry/archive/2005/02/25/301441.aspx
SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]);
SqlDataAdapter da=new SqlDataAdapter("select * from tb1",conn);
DataSet ds=new DataSet();
da.Fill(ds,"table1");
DataTable dt=ds.Tables["table1"];
string name=System.Configuration.ConfigurationSettings.AppSettings["downloadurl"].ToString()+DateTime.Today.ToString("yyyyMMdd")+new Random(DateTime.Now.Millisecond).Next(10000).ToString()+".csv";//存放到web.config中downloadurl指定的路径,文件格式为当前日期+4位随机数
FileStream fs=new FileStream(name,FileMode.Create,FileAccess.Write);
StreamWriter sw=new StreamWriter(fs,System.Text.Encoding.GetEncoding("gb2312"));
sw.WriteLine("自动编号,姓名,年龄");
foreach(DataRow dr in dt.Rows)
{
sw.WriteLine(dr["ID"]+","+dr["vName"]+","+dr["iAge"]);
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(name));
Response.ContentType = "application/ms-excel";// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.WriteFile(name); // 把文件流发送到客户端
Response.End();
表的结构同此文:http://blog.csdn.net/lovecherry/archive/2005/02/25/301441.aspx
SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]);
SqlDataAdapter da=new SqlDataAdapter("select * from tb1",conn);
DataSet ds=new DataSet();
da.Fill(ds,"table1");
DataTable dt=ds.Tables["table1"];
string name=System.Configuration.ConfigurationSettings.AppSettings["downloadurl"].ToString()+DateTime.Today.ToString("yyyyMMdd")+new Random(DateTime.Now.Millisecond).Next(10000).ToString()+".csv";//存放到web.config中downloadurl指定的路径,文件格式为当前日期+4位随机数
FileStream fs=new FileStream(name,FileMode.Create,FileAccess.Write);
StreamWriter sw=new StreamWriter(fs,System.Text.Encoding.GetEncoding("gb2312"));
sw.WriteLine("自动编号,姓名,年龄");
foreach(DataRow dr in dt.Rows)
{
sw.WriteLine(dr["ID"]+","+dr["vName"]+","+dr["iAge"]);
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(name));
Response.ContentType = "application/ms-excel";// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.WriteFile(name); // 把文件流发送到客户端
Response.End();
ASP.NET中发送要求SMTP认证的邮件
作者:小轩 日期:2009-04-02
using System.Web.Mail;
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.BodyFormat = MailFormat.Html;//设置为HTML格式
//设置为需要用户验证
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//设置验证用户名(把my_username_here改为你的验证用户名)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here");
//设置验证密码(把password改为你的验证密码)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password");
SmtpMail.SmtpServer = "mail.mycompany.com"; //邮件服务器地址
SmtpMail.Send( mail );
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.BodyFormat = MailFormat.Html;//设置为HTML格式
//设置为需要用户验证
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//设置验证用户名(把my_username_here改为你的验证用户名)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here");
//设置验证密码(把password改为你的验证密码)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password");
SmtpMail.SmtpServer = "mail.mycompany.com"; //邮件服务器地址
SmtpMail.Send( mail );
gridview自动编号 等
作者:小轩 日期:2009-03-17
双击GridView的OnRowDataBound事件;
在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行 //清清月儿http://blog.csdn.net/21aspnet
if (e.Row.RowType == DataControlRowType.DataRow)
{
////鼠标经过时,行背景色变
//e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
////鼠标移出时,行背景色变
//e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
////当有编辑列时,避免出错,要加的RowState判断
//if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
//{
// ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
//}
}
if (e.Row.RowIndex != -1)
{
在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行 //清清月儿http://blog.csdn.net/21aspnet
if (e.Row.RowType == DataControlRowType.DataRow)
{
////鼠标经过时,行背景色变
//e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
////鼠标移出时,行背景色变
//e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
////当有编辑列时,避免出错,要加的RowState判断
//if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
//{
// ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
//}
}
if (e.Row.RowIndex != -1)
{
Flash动画







