62,046
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
BindTypeData();//绑定分类
}
//绑定分类
protected void BindTypeData()
{
DataSet ds = new NewsTypeBLL().GetClassList(0); //获取所有分类信息
this.dropDownNewsType.DataSource = ds.Tables[0].DefaultView;
this.dropDownNewsType.DataBind();
this.dropDownNewsType.Items.Clear();
this.dropDownNewsType.Items.Add(new ListItem("按分类查询", "0"));
foreach (DataRow dr in ds.Tables[0].Rows)
{
int ClassTj = Convert.ToInt32(dr["ClassTj"]);
string ClassId = dr["ClassId"].ToString().Trim(); //绑定分类ID
string ClassName = dr["ClassName"].ToString().Trim(); //绑定分类名称
if (ClassTj == 1)
{
this.dropDownNewsType.Items.Add(new ListItem(ClassName, ClassId));
}
else
{
ClassName = "├ " + ClassName;
ClassName = StringHelper.StringOfChar(ClassTj - 1, " ") + ClassName;
this.dropDownNewsType.Items.Add(new ListItem(ClassName, ClassId));
}
}
}
//查询按钮事件
protected void btnSearch_Click(object sender, EventArgs e)
{
string TypeId = dropDownNewsType.SelectedValue;
CompanyArticleRepeaterList.DataSource = articleBLL.SearchNews(TypeId);
CompanyArticleRepeaterList.DataBind();
}
//业务逻辑层省略
.
.
.
//数据访问层
public DataSet SearchNews(string NewsTitle,string TypeId,int IsCmd)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from Article where 1=1");
if (TypeId != "0")
{
strSql.Append(" and TypeId = '" + TypeId + "'");
}
return GetDataset(CommandType.Text, strSql.ToString()); //执行SQL,返回结果
}