日期:2014-05-20 浏览次数:20916 次
codepublicpartialclass tuandui_huwai_Default : System.Web.UI.Page {protectedstring news;publicstaticstring connectString= Convert.ToString(ConfigurationManager.ConnectionStrings["conn"]); SqlConnection con=new SqlConnection(connectString);protectedvoid Page_Load(object sender, EventArgs e) { kcbind(); }void kcbind() {string sql="select news_id,news_name from news"; con.Open(); SqlCommand cmd=new SqlCommand(sql, con); SqlDataReader dr= cmd.ExecuteReader();string s=""; s+="<ul>";while (dr.Read()) { s+="<li><a href=news.aspx?id="+ dr["news_id"]+">"+ dr["news_name"]+"</a></li>"; } s+="</ul>"; con.Close(); news= s; } }
DataTable dt = ds.Tables[0]; if (dt.Rows.Count / pagesize >= 1) { int maxi = 0; //取出所有新闻列表 if (dt.Rows.Count % pagesize == 0) { maxi = dt.Rows.Count / pagesize; } else { maxi = (dt.Rows.Count / pagesize) + 1; } for (int i = 0; i < maxi; i++) // i 分页的页数(生成页面的个数) { StringBuilder sb = new StringBuilder();//新闻列表 //生成新闻列表 for (int h = i * pagesize; h < (i + 1) * pagesize; h++)// { if (h < dt.Rows.Count) { sb.Append("<li><span class=\"newstitle\"><a href=\"/news/" + dt.Rows[h] ["ID"].ToString() + ".html\" title=\"" + dt.Rows[h]["Name"].ToString() + "\">" + dt.Rows[h]["Name"].ToString() + "</a></span><div class=\"clear\"></div></li>"); } }