using System.Data.OleDb;
using System.Data;
----------------------------获取数据-------------------------------
OleDbConnection conn = new OleDbConnection(DB.conn);
conn.Open();
string sql = "select * from cxy_pageC where id=1";
OleDbCommand cmd = new OleDbCommand(sql,conn);
OleDbDataReader dr = cmd.ExecuteReader();
dr.Read();
----------------------------格式化日期时间-----------------------
<%# DataBinder.Eval(Container.DataItem, "addtime", "{0:yyyy-MM-dd}")%>
--------------------------------图片路径--------------------------
UpLoadFile/Small_Img/<%#Eval("picurl")%>
--------------------------------详细页链接--------------------------
product_details.aspx?id=<%#Eval("id") %>
news_details.aspx?id=<%#Eval("id") %>
-------------------------------截取标题--------------------------
<%#Eval("title").ToString().Length>=35?Eval("title").ToString().Substring(0,35):Eval("title") %>
----------------------------------获取new图片--------------------------------
<%#getimg(Convert.ToDateTime(Eval("addtime")))%>
public string getimg(DateTime data)
{
string dt1 = data.ToString();
string dt2 = System.DateTime.Now.ToLocalTime().ToString();
TimeSpan sjc = Convert.ToDateTime(dt2) - Convert.ToDateTime(dt1);
double day = sjc.TotalDays;
if (day <= 7)
{
return "";
}
else {
return "";
}
}
----------------------------------绑定数据(带分页)----------------------------
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> -----------引用命名空间
-------分页控件
暂无资料... --------没有数据时显示
public void dataBind() {
string sql = "";
if (Request.QueryString["class"] != "" && Request.QueryString["class"] != null)
{
sql = "select * from cxy_NewsC where clsid=" + Request.QueryString["class"].ToString()+" order by id desc";
}
else
{
sql = "select * from cxy_NewsC where clsid in (92,98,99) order by id desc";
}
OleDbConnection conn = new OleDbConnection(DB.conn);
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(sql,conn);
DataSet ds = new DataSet();
DataSet ds2 = new DataSet();
da.Fill(ds2);
AspNetPager1.PageSize = 10;
AspNetPager1.RecordCount = (int)ds2.Tables[0].Rows.Count;
if (AspNetPager1.RecordCount == 0) {
noinf.Visible = true;
}
da.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize,"aaa");
news_list.DataSource = ds;
news_list.DataBind();
conn.Close();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
dataBind();
}
--------------------------------------返回----------------------
------------------------------------获取编号(写在pageload事件中)-------------------------------------
protected void getnum()
{
for (int i = 0; i < news_list.Items.Count; i++) {
Label lb = news_list.Items[i].FindControl("num") as Label;
if (i.ToString().Length == 1)
{
lb.Text = "0" + (i+1);
}
else
{
lb.Text = (i+1).ToString() ;
}
}
}
------------------------------------强制不缓存------------------
Response.Buffer = true;
Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
Response.Expires = 0;
Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "No-Cache");
-------------------------过滤HTML-----------------------------------
public string checkStr(string html)
{
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"标记
html = regex2.Replace(html, ""); //过滤href=javascript: () 属性
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, ""); //过滤iframe
html = regex5.Replace(html, ""); //过滤frameset
html = regex6.Replace(html, ""); //过滤frameset
html = regex7.Replace(html, ""); //过滤frameset
html = regex8.Replace(html, ""); //过滤frameset
html = regex9.Replace(html, "");
//html = html.Replace(" ", "");
html = html.Replace("", "");
html = html.Replace("", "");
return html;
}
---------------------------获取子分类--------------------------------
protected string getchild(int id)
{
OleDbConnection conn = new OleDbConnection(DB.conn);
conn.Open();
string sql = "select * from cxy_clsC where clsid="+id;
OleDbCommand cmd = new OleDbCommand(sql, conn);
OleDbDataReader dr = cmd.ExecuteReader();
string idstr = "";
while (dr.Read()) {
idstr += dr["id"].ToString()+",";
}
if (idstr == "")
{
return "0";
}
else
{
return idstr;
}
}
--------------------------保存留言-----------------------------------
protected void submit_Click(object sender, EventArgs e)
{
string name2 = name.Value;
string company2 = company.Value;
string area2 = site.Value;
string tel2 = telephone.Value;
string email2 = mail.Value;
string address2 = address.Value;
string title2 = theme.Value;
string content2 = text.Value;
string sql = "insert into cxy_MessageC (name,company,area,tel,email,address,title,content) values (@name,@company,@area,@tel,@email,@address,@title,@content)";
OleDbConnection conn = new OleDbConnection(DB.conn);
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql,conn);
cmd.Parameters.AddWithValue("@name",name2);
cmd.Parameters.AddWithValue("@company", company2);
cmd.Parameters.AddWithValue("@area", area2);
cmd.Parameters.AddWithValue("@tel", tel2);
cmd.Parameters.AddWithValue("@email", email2);
cmd.Parameters.AddWithValue("@address", address2);
cmd.Parameters.AddWithValue("@title", title2);
cmd.Parameters.AddWithValue("@content", content2);
try{
cmd.ExecuteNonQuery();
}catch(Exception ex){
Response.Write("留言失败!错误信息:
"+ex.StackTrace);
Response.End();
}
Response.Write("");
}
---------------------------------------------------QQ在线交谈
---------------------------------------------------------页面淡入淡出
----------------------------------------------页面加载完成后弹出对话框
ScriptManager.RegisterStartupScript(this, this.GetType(), "OK", "alert('XXXXXX');", true);
-----------------------------------------------thickbox 效果需导入的文件
-------------------------------------------------ajax核心代码
-------------------------添加IOS图标-------------------------
------------------------------动态网页关键字--------------------------------
HtmlMeta desc = new HtmlMeta();
desc.Name = "Description";
desc.Content = "我的网站描述";
Page.Header.Controls.Add(desc);
//Keyword网页关键字
HtmlMeta keywords = new HtmlMeta();
keywords.Name = "keywords";
keywords.Content = "我的网站关键字";
Page.Header.Controls.Add(keywords);