platform/ShowNewsCate.aspx.cs

115 lines
3.3 KiB
C#
Raw Normal View History

2024-02-18 23:33:54 +08:00
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using DeiNiu.Utils;
using DeiNiu.wms.Logical;
public partial class ShowNewsCate : Page
{
private string cateId;
private string upId;
protected void Page_Load(object sender, EventArgs e)
{
cateId = Request.QueryString["cateId"];
upId = Request.QueryString["upId"];
if (!IsPostBack)
bindData();
}
private void InitializeComponent()
{
}
void bindData()
{
LPublicNews logic = new LPublicNews();
DataView dv = logic.QueryTopCatagory().DefaultView;
dv.RowFilter = "ID='" + upId+"'";
RepeaterTop.DataSource = dv;
RepeaterTop.DataBind();
RepeaterMarquee.DataSource = logic.QueryMarqueen().DefaultView;
RepeaterMarquee.DataBind();
}
protected void RepeaterTop_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rpColumnNews = (Repeater)e.Item.FindControl("RepeaterSecond");
//找到分类Repeater关联的数据项
DataRowView rowv = (DataRowView)e.Item.DataItem;
//提取分类ID
string authID = Convert.ToString(rowv["ID"]);
//里面的Repeater
LPublicNews logic = new LPublicNews();
DataView dv = logic.QueryPublicInfomation().DefaultView;
// dv.RowFilter = "auth_uplevel='" + authID + "' and auth_marqueen=0 ";
dv.RowFilter = "ID='" + cateId + "'";
rpColumnNews.DataSource = dv;
rpColumnNews.DataBind();
}
}
protected void RepeaterSecond_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rpColumnNews = (Repeater)e.Item.FindControl("RepeaterThird");
//找到分类Repeater关联的数据项
DataRowView rowv = (DataRowView)e.Item.DataItem;
//提取分类ID
string authID = Convert.ToString(rowv["ID"]);
//里面的Repeater
LPublicNews logic = new LPublicNews();
DataView dv = logic.QueryNews(Convert.ToInt32(authID)).DefaultView;
dv = GetTopDataViewRows(dv,10);
rpColumnNews.DataSource = dv;
rpColumnNews.DataBind();
}
}
public string FormatShowContent(string titlecontent, int titlelength)
{
if (titlecontent.Length > titlelength)
{
return titlecontent.Substring(0, titlelength);
}
else
{
for (int i = 0; i < titlelength - titlecontent.Length;i++ )
titlecontent += "&nbsp;";
return titlecontent;
}
}
private DataView GetTopDataViewRows(DataView dv, int n)
{
DataTable dt = dv.Table.Clone();
for (int i = 0; i < n - 1; i++)
{
if (i >= dv.Count)
{
break;
}
dt.ImportRow(dv[i].Row);
}
return new DataView(dt, dv.RowFilter, dv.Sort, dv.RowStateFilter);
}
}