关于搜索:
点击搜索后跳转到本页。
response.redirect("userlist.aspx?xxx="+搜索关键字);
绑定数据的时候
判断是由否有搜索关键字。有则加上搜索关键字;
private void BindData()
{
try
{
string strWhere = "1=1";
if (Request["typeid"] != null)
{
if (Request["typeid"]!="0")
{
strWhere += " and CateId=" + Request["typeid"];
}
}
if (Request["title"] != null)
{
strWhere += " and ArtTitle like '%" + Request["title"]+"%'";
}
int total = 0;
var dt = news.GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, strWhere, "ArtAddTime desc, ArtId asc", out total).Tables[0];
AspNetPager1.RecordCount = total;
if (dt.Rows.Count > 0)
{
repArticles.DataSource = dt;
repArticles.DataBind();
lbText.Text = "";
lbText.Visible = false;
}
else
{
lbText.Text = "没有可显示的数据!";
lbText.Visible = true;
}
}
catch (Exception)
{
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
Response.Redirect("list.aspx?typeid=" + ddlCategory.SelectedValue + "&title=" + SearchText.Text.Trim());
}
关于页面的导航:
如:首页--新闻中心--行业新闻
1.根据传过来的分类id获取他的CatePath路径(0,1,5),
/// <summary>
/// 获取该分类的所有顶级。
/// </summary>
/// <param name="id"></param>
public List<Lvegu.Model.Category> GetEachTop(int id)
{
Lvegu.Model.Category model = GetModel(id);
string idlist = "";
List<Lvegu.Model.Category> list = new List<Lvegu.Model.Category>();
//若已是最顶级的分类,则把该model加到list返回
if (model.CatePId == 0)
{
list.Add(model);
}
else
{
//这样拼出来就是1,5
idlist = model.CatePath.Substring(2, model.CatePath.Length - 2) + model.CateId;
//这里当然就是CateId in(1,5),他的所有顶级分类据得到了
DataSet ds = dal.GetList("CateId in(" + idlist + ")");
//再转为list类型
list = DataTableToList(ds.Tables[0]);
}
return list;
}
那么在页面只需下面的绑定
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
var cid = Request["cid"] == null ? 6 : int.Parse(Request["cid"]);
var list = new Lvegu.BLL.Category().GetEachTop(cid);
repSiteMap.DataSource = list;
repSiteMap.DataBind();
}
catch (Exception)
{
}
}
}
此处用用户控件(可以重复使用,方便)
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UCMapSite1.ascx.cs" Inherits="Controls_UCMapSite1" %>
<div class="the">
<span>您当前的位置 - </span><a href="index.aspx">首页</a>
<asp:Repeater ID="repSiteMap" runat="server">
<ItemTemplate>
- <a href='About.aspx?cid=<%#Eval("CateId") %>'><%#Eval("CateName") %></a>
</ItemTemplate>
</asp:Repeater>
</div>
关于左侧菜单:
(左侧菜单一般是根据首页点击导航到内页,点击不同导航,则内页的左侧菜单也跟着变化)
1.根据传过来的分类获取该分类的顶级分类
2.再根据这个顶级分类的id获取他下面的所有自分类(递归获取)
private void BindMenu()
{
try
{
//根据传过来的cid获取顶级分类id
var cid = Request["cid"] == null ? 6 : int.Parse(Request["cid"]);
var model = cate.GetModel(cid);
//若传过来的分类不存在返回
if (model == null)
{
return;
}
else
{
//CatePath的格式0,1,4,8 其实就是所有的父级分类的id/
//去掉0,取第二个就是最顶级的分类id了。
//此处不能用model.CatePath.Substring(2, 1)这种方法
//因为第二个有可能是1位数、也有可能是2位数,还有可能是3位数
String strtopid = model.CatePath.Split(new Char[] { ',' })[1].ToString();
//如果model的父级id为0,则传过来的是最顶级的分类,如不是则用strtopid
var topid = model.CatePId == 0 ? model.CateId : int.Parse(strtopid);//顶级id
var dt = cate.GetMyList("CatePId=" + topid.ToString() + " order by CateSort asc");
//左侧菜单标题
menuTitle.Text = model.CatePId == 0 ? model.CateName : cate.GetModel(topid).CateName;
repMenu.DataSource = dt;
repMenu.DataBind();
}
}
catch (Exception)
{
}
}