#region 参数属性
//排列方式
int m_Type = 0;
public int Type
{
get { return m_Type; }
set { m_Type = value; }
}
//商品类别
int m_ProductClass = -1;
public int ProductClass
{
get { return m_ProductClass; }
set { m_ProductClass = value; }
}
//品牌类型
int m_BrandCategory = 0;
public int BrandCategory
{
get { return m_BrandCategory; }
set { m_BrandCategory = value; }
}
//显示条数
int m_ListNum = 0;
public int ListNum
{
get { return m_ListNum; }
set { m_ListNum = value; }
}
//排序字段
string m_Orderfield = "Id";
public string Orderfield
{
get { return m_Orderfield; }
set { m_Orderfield = value; }
}
//WHERE条件
string m_WhereStr = "";
public string WhereStr
{
get { return m_WhereStr; }
set { m_WhereStr = value; }
}
string m_Text = "";
public string Text
{
get { return m_Text; }
set { m_Text = value; }
}
#endregion
#region 获取商品列表HTML信息
public void GetListMsg()
{
StringBuilder str = new StringBuilder();
try
{
UcOpration opt = new UcOpration();
opt.ProductClass = ProductClass;
opt.BrandCategory = BrandCategory;
opt.ListNum = ListNum;
opt.Orderfield = Orderfield;
opt.WhereStr = WhereStr;
str.Append("<ul>");
IList list = idbuc.ReadList(opt);
for (int i = 0; i < list.Count; i++)
{
UcList uclist = (UcList)list[i];
string listStr = GetContent();
if (Type == 1)
listStr = string.Format(listStr, "/Product/ProductDetail.aspx?id=" + uclist.Id, uclist.Img, uclist.ProductName, uclist.ProductName, uclist.OldPrice, uclist.NewPrice);
else if (Type == 2)
listStr = string.Format(listStr, "/Product/ProductDetail.aspx?id=" + uclist.Id, uclist.Img, uclist.ProductName, uclist.ProductName, uclist.NewPrice);
else if (Type == 3)
listStr = string.Format(listStr, "/Product/ProductDetail.aspx?id=" + uclist.Id, uclist.ProductName);
str.Append(listStr);
}
str.Append("</ul>");
}
catch (Exception ex)
{
str.Append(ex.Message);
}
Text = str.ToString();
}
//内容信息
private string GetContent()
{
if (Type == 1)
return @"
<li>
<a href='{0}' target='_blank'>
<img src='{1}' alt='{2}' />
<div class='item'>
{3}
<label class='original-price'>{4}</label>
<label class='special-price'>{5}</label>
</div>
</a>
</li>";
else if (Type == 2)
return @"
<li>
<a href='{0}' target='_blank'>
<img src='{1}' alt='{2}' />
<div>{3}</div>
<span><label class='special-price'>{4}</label></span>
</a>
</li>";
else
return @"
<li>
<a href='{0}' target='_blank'>{1}</a>
</li>";
}
#endregion
#region 输出商品列表HTML信息
protected override void Render(HtmlTextWriter writer)
{
writer.Write(this.Text.ToString());
}
#endregion
源代码调用
<uc1:ProductListTag id="Tag1" Type="1" ProductClass="-1" BrandCategory="0" ListNum="6" Orderfield="Id" WhereStr="" runat = "server" ></uc1:ProductListTag>