Asp.Net生成静态页面
从数据库取出数据然后动态的生成html静态页面。这种技术特别是在拥有大量页面的网站中显的特别的重要
具体步骤我详细的写一下
1.建立静态模板页面。也就是建立起模板页面的架构
2.然后从后台数据库中提取内容,进行替换
3.把替换后的字符串写入中
我也按照上面的顺序做一下吧
首先建立一个模板Html取名ModelHtml.htm.用于静态页面的布局
<html>
<title></title>
<head></head>
<body>
<table>
<tr>
<td>ArticleTitle<td>
</tr>
<tr>
<td>ArticleContent</td>
</tr>
</table>
<body>
</html>
然后就要从数据库中提取数据了
我要把数据库中的内容用datalist呈现出来
建立一个WebForm,然后放置一个datalist控件
<asp:DataList id="dlist" runat="server" >
<ItemTemplete>
<table>
<tr>
<td>文章ID:</td><td><%# DataBinder.Eval(Container.DateItem,"ID")%></td>
<td>文章标题</td><td><%# DataBinder.Eval(Container.DataItem,"Articletitle")%></td>
<td><asp:LinkButton id="linkBtn" runat="server">转换静态页面</td>
<tr>
<table>
</ItemTemplete>
</asp:DataList>
前台基本完成了
后台的代码如下
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
SqlConnection con=new SqlConnection("Data Source=DADI-PC;Initial Catalog=db_test;Persist Security Info=True;User ID=sa;Password=sa");
string strSql = "select * from tb_test where ID='" + DataList1.DataKeys[e.Item.ItemIndex].ToString()+"'";
con.Open();
SqlCommand cmd = new SqlCommand(strSql, con);
SqlDataReader myReader = cmd.ExecuteReader();
myReader.Read();
if(myReader.HasRows)
{
WriteFile(myReader["ArticleTitle"].ToString(), myReader["ArticleContent"].ToString(), myReader["ID"].ToString());
Response.Write("<mce:script type="text/javascript">
相关文档:
一.摘要
和自身水平有关, 我总喜欢写入门级别的文章.比如虽然做项目用过一个内部的MVC框架, 但是当看到ASP.NET MVC时我却还是不知道从哪里入手开始学习的好.于是我写下这篇入门级的系列文章, 将老赵(Jeffrey Zhao)的ASP.NET MVC系列视频课程学到的知识再理解和再消化, 让最笨的人也能跟着我学懂ASP.NET MVC
二. ......
专门给你写了个,你看一下,说明下这里没有考虑到数据的有效性,需要的话自己加上。
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.WebCon ......
1.
保证xp环境已经安装有.net framework 3.5 sp1、asp.net mvc 1.0或2.0
2.
由于iis5.1只有一个默认网站,因此先将默认网站的其他文件放到其他位置,将项目文件拷贝到默认网站所在目录(一般是:C:\Inetpub\wwwroot),修改相应的连接字符串。
3. ......
Asp.net常用的51个代码(非常实用)
1.//弹出对话框.点击转向指定页面
CODE:Response.Write("<script>window.alert('该会员没有提交申请,请重新提交!')</script>");
Response.Write("<script>window.location ='http://www.51aspx.com/bizpulic/upmeb.aspx'</script>");
2. ......