日期:2014-05-17 浏览次数:20489 次
protected void CommentBindData()
{
//1.创建一个StringBuilder保存字符串
StringBuilder strHtml = new StringBuilder();
//2.查询数据库保存在DataSet.DataTable里面,并用for遍历,代替数据绑定控件
var modelList = WebApp.DAL.DBHelper.Query("select ID,Title,AddTime from Comment").Tables[0];
for (int i = 0; i < modelList.Rows.Count; i++)
{
//3.for遍历拼接html,并返回输出
strHtml.AppendFormat("<div id='div1'>{0}</div>", modelList.Rows[i]["Title"].ToString());
strHtml.AppendFormat("<div id='div2'>{0}</div>", modelList.Rows[i]["AddTime"].ToString());
}
Response.Write(strHtml.ToString());
}