| 飞凡's profile飞凡的共享空间BlogNetwork | Help |
飞凡的共享空间 |
|||||
|
August 08 一个过滤有攻击性字符的方法//过滤特殊字符串 public static string FiltrateWord(string str) { str = str.Replace("&", "&"); str = str.Replace("<", "<"); str = str.Replace(">", ">"); str = str.Replace("'", "‘"); str = str.Replace("*", "×"); //str = str.Replace("\n", " "); //str = str.Replace("\r\n", " "); str = str.Replace("?", "?"); str = str.Replace("select", " "); str = str.Replace("insert", " "); str = str.Replace("update", " "); str = str.Replace("delete", " "); str = str.Replace("create", " "); str = str.Replace("drop", " "); str = str.Replace("delcare", " "); str = str.Replace("^", " "); str = str.Replace("%", " %"); str = str.Replace("+", "+"); str = str.Replace("-", "-"); str = str.Replace("exec", " "); str = str.Replace(":", ":"); str = str.Replace(";", ";"); return str; } August 04 关于datalist分页的问题 近来要做一个品牌的展示,做成如下样子
××× ××× ×××
××× ××× ×××
××× ××× ×××
想来想去不能用gridview就只能用datalist,用datalist的时候没有gridview那样自带有分页的功能
所以就自己写代码了。不过今天在csdn上逛无意看到有网友出供用asppager来分页
自己做了几个demo果然是好用,把代码贴在下面供参考了
控件的下载点 http://www.webdiyer.com/
1.在vs.net2005中,该控件并不能自动添加到工具面板中,需要手动添加项,选定AspNetPager.dll,即可
2.在codeBehind的cs文件中,要using Wuqi.Webdiyer;
3.写好ChangePage事件后,要与aspnetpager控件相关联
以下是一段示例代码:
数据库用的是access。。。。。下一段是sqlserver
...................................................................
前台default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="test_Default" StylesheetTheme="default" %> <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> <asp:DataList ID="DataList1" runat="server"> <ItemTemplate> ProductName: <asp:Label ID="ProductNameLabel" runat="server" Text='<%# Eval("ProductName") %>'> </asp:Label><br /> <br /> </ItemTemplate> </asp:DataList> <webdiyer:aspnetpager id="pager1" runat="server" onpagechanged="ChangePage"></webdiyer:aspnetpager> </div> </form> </body> </html> 后置代码:default.aspx.cs
using System;
using System.Data; 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 cpp114.tools.oledb; using System.Data.OleDb; using Wuqi.Webdiyer; public partial class test_Default : System.Web.UI.Page
{ protected OleDbConnection conn = new OleDbConnection(); protected OleDbCommand cmd = new OleDbCommand(); protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack) { initdb(); conn.Open(); cmd.CommandText = "select count(*) from t_product"; pager1.RecordCount = (int)cmd.ExecuteScalar(); conn.Close(); BindData(); } }
//初始化连接对象 protected void initdb(){ conn.ConnectionString = oledbtool.myConnStr + Server.MapPath(oledbtool.mydbName); cmd.Connection = conn; } //数据绑定
protected void BindData() { initdb(); OleDbDataAdapter sda = new OleDbDataAdapter("select * from t_product",conn); DataSet ds = new DataSet(); //sda.Fill(ds, 10, 10, "temptbl"); sda.Fill(ds, pager1.PageSize * (pager1.CurrentPageIndex - 1), pager1.PageSize, "temptbl"); DataList1.DataSource = ds.Tables["temptbl"]; DataList1.DataBind(); } //翻页事件
protected void ChangePage(object src, PageChangedEventArgs e) { pager1.CurrentPageIndex = e.NewPageIndex; BindData(); } }
-----------------------------------------------------------------------------------------
用到的一般情况,在sqlserver情况下copy就要以用了,但在html码中也要改。一般用的就是这种了。。。。
using System;
using System.Data; 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 Wuqi.Webdiyer; using System.Data.SqlClient; public partial class Default4 : System.Web.UI.Page { protected SqlConnection mycon = new SqlConnection(); protected SqlCommand cmd = new SqlCommand(); protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack) { initdb(); mycon.Open(); cmd.CommandText = "select count(*) from product"; AspNetPager1.RecordCount = (int)cmd.ExecuteScalar(); mycon.Close(); BindData(); }
}
//初始化连接对象
protected void initdb() { DB db = new DB(); mycon = db.GetConnetcion(); cmd.Connection = mycon; } //数据绑定
protected void BindData() { initdb(); SqlDataAdapter sda = new SqlDataAdapter("select * from product", mycon); DataSet ds = new DataSet(); //sda.Fill(ds, 10, 10, "temptbl"); sda.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "temptbl"); DataList1.DataSource = ds.Tables["temptbl"]; DataList1.DataBind(); } //翻页事件 protected void AspNetPager1_PageChanging(object src, PageChangingEventArgs e) { AspNetPager1.CurrentPageIndex = e.NewPageIndex; BindData(); } } July 31 谈论 什么是Web Service
引用 什么是Web Service 关于如何得到web.config中的数据库连接字符串前几天去CSDN看到相关的问题,
近来也在做站点后台。
关于如何得到web.config中的数据库连接字符串
在vs05中用如下代码
public SqlConnection GetConnetcion ()
{ string ConnectionString = ConfigurationManager.ConnectionStrings["dbConnectionString"].ToString(); SqlConnection Connection = null;
try { Connection = new SqlConnection(ConnectionString); Connection.Open(); } catch (Exception ex) { } finally { Connection.Close(); } return Connection; } 以上代码以dbConnectionString为例,当然这个是由web.config中的情况定义的了。。。
这样返回一个sqlconnection类,当然,异常的处理机制可以由具体情况自己写了。 一个好用的MD5加密类代码 在C#中用MD5类进行加密得到128位的哈希散列,是一个byte型数组,而一般希望得到一个字符串用于保存到数据库
下面这个类实现了由数组到字符串的转化
public string PwdEncrypt(string Pwd)
{ MD5 md5 = new MD5CryptoServiceProvider(); byte[] data = System.Text.Encoding.Default.GetBytes(Pwd); byte[] md5data = md5.ComputeHash(data); md5.Clear();
string Str = ""; for (int i = 0; i < md5data.Length - 1; i++) { Str += md5data[i].ToString("x").PadLeft(2, '0'); } return Str; } 直接可以xcopy......汗。。。
|
||||
|
|