using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Starock.BLL;
using Starock.Model;
using Starock.Comm;
public partial class style_inPage : System.Web.UI.Page
{
BLL_StyleClass myStyleClass = new BLL_StyleClass();
BLL_SytleInfo myStyleInfo = new BLL_SytleInfo();
Comm myComm = new Comm();
static int iClass = 0;
static int iPage = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request["class"] != null)
{
iClass = Convert.ToInt32(Request["class"].ToString());
}
ShowList(iClass, iPage);
}
}
public void ShowList(int iClass, int iPage)
{
lTest.Text = iClass.ToString();
DataList dlInfo = new DataList();
dlInfo.ID = "dlInfo";
dlInfo.DataKeyField = "ID";
dlInfo.Width = 590;
dlInfo.RepeatColumns = 4; //一行4列
dlInfo.RepeatDirection = RepeatDirection.Horizontal; //横向显示
dlInfo.ItemDataBound += new DataListItemEventHandler(dlInfo_ItemDataBound); //添加数据绑定事件
dlInfo.ItemTemplate = new CMyTemplate("lItem"); //创建模板列,通过构造函数初始化控件名称
dlInfo.DataSource = myStyleInfo.GetList(iClass);
dlInfo.DataBind();
//this.Controls.Add(dlInfo); //将DATALIST添加到当前页面中(这里因为要返回HTML代码,所以屏蔽该句)
//把DataList输出成HTML
Response.Write(this.GetStringByControl(dlInfo));
}
private void dlInfo_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
Label lItem;
int ID = 0;
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
lItem = (Label)e.Item.FindControl("lItem");
if (lItem != null)
{
ID = Convert.ToInt32(((DataRowView)e.Item.DataItem).Row["ID"].ToString());
lItem.Text = "<table width='146' border='0' cellspacing='0' cellpadding='0'><tr>" +
"<td><div align='center'><a href='./images/style/" + GetPhotoBig(ID) + "' target='_blank' title='"+GetInfo(ID).StyleName +"' rel='lightbox[roadtrip]'><img src='./images/style/"+GetPhoto(ID)+"' width='125' height='125' border='0' /></a></div></td>" +
"</tr><tr><td> </td></tr></table>";
}
}
}
public string GetStringByControl(System.Web.UI.Control theControl)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter writer = new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(writer);
theControl.RenderControl(htw);
return sb.ToString();
}
public string GetPhoto(int ID)
{
StyleInfo oInfo = myStyleInfo.GetInfo(ID);
if (oInfo.Photo != null)
{
return oInfo.Photo;
}
else
{
return "null.jpg";
}
}
public string GetPhotoBig(int ID)
{
StyleInfo oInfo = myStyleInfo.GetInfo(ID);
if (oInfo.Photo_Big != null)
{
return oInfo.Photo_Big;
}
else
{
return "null_big.jpg";
}
}
public StyleInfo GetInfo(int ID)
{
return myStyleInfo.GetInfo(ID);
}
}
class CMyTemplate : ITemplate
{
private string pControlName; //控件名称
public CMyTemplate(string ControlName)
{
pControlName = ControlName;
}
public void InstantiateIn(Control container)
{
Label lItem = new Label();
lItem.ID = pControlName;
container.Controls.Add(lItem);
}
}