实现效果为http://www.zbsydc.com/merchant/index.aspx

需要根据不同的条件选择情况,生成不同的URL查询字符串组合。
后台代码 index.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Logic.BLL;
using Logic.Model;
using Logic.Common;
using System.IO;
using System.Collections.Generic;
using System.Collections.Specialized;
public partial class merchant_Index : UserBasePage
{
public string curclass = string.Empty;
public StringBuilder are = new StringBuilder();
public StringBuilder sb = new StringBuilder();
public StringBuilder BusUrl = new StringBuilder();
public StringBuilder FirstUrl = new StringBuilder();
public StringBuilder NewshopUrl = new StringBuilder();
public StringBuilder ShopareaUrl = new StringBuilder();
public String url = string.Empty;
public string bussiness_type = string.Empty;
public string first_choice = string.Empty;
public string new_shop_type = string.Empty;
public string shop_area = string.Empty;
public string[] keys = new string[4]{"bussiness_type1","new_shop_type","shop_area","first_choice"};
public Dictionary<string, string> oldlink = new Dictionary<string, string>();
//生成相应的搜索查询字符串
protected void Page_Load(object sender, EventArgs e)
{
BindHouseList();
BindTophouse();
url = HttpContext.Current.Request.RawUrl;
SetBusUrl();
}
//连接式搜索连接形成
private void SetBusUrl()
{
//过滤掉原有的变量 重新生成链接
String OutHref = "/Merchant/index.aspx?";
if (Request.QueryString.Count != 0)
{
//过滤了bussinesstype
//遍历所有参数值 看有没有
foreach (string keyall in keys)
{
sb.Length = 0;
int ii = 1;
foreach (string key in Request.QueryString.Keys)
{
if (keyall != key)
{
if (ii == Request.QueryString.Keys.Count)
{
sb.AppendFormat("{0}={1}", key, Request.QueryString[key]);
}
else
{
sb.AppendFormat("{0}={1}&", key, Request.QueryString[key]);
}
}
ii++;
}
oldlink.Add(keyall, OutHref + sb.ToString());
}
//newshop
//first
//area
}
else
{
foreach (string keyall in keys)
{
oldlink.Add(keyall, OutHref);
}
}
foreach (KeyValuePair<int, string> item in Common.BussinessType())
{
string curclass = string.Empty;
if (item.Key != -1)//不限不需要加入参数
{
if (Request.QueryString["bussiness_type1"] != null && Request.QueryString["bussiness_type1"].ToString() == item.Key.ToString()) curclass = " class=\"cur\" ";
BusUrl.Append("<a href=\"" + oldlink["bussiness_type1"] + "&bussiness_type1=" + item.Key + "\" " + curclass + " >" + item.Value + "</a>");
}
else
{
if (string.IsNullOrEmpty(Request.QueryString["bussiness_type1"])) curclass = " class=\"cur\" ";
BusUrl.Append("<a href=\"" + oldlink["bussiness_type1"] + "\" " + curclass + " >不限</a>");
}
}
foreach (KeyValuePair<int, string> item in Common.FirstChoice())
{
string curclass = string.Empty;
if (item.Key != -1)
{
if (Request.QueryString["first_choice"] != null && Request.QueryString["first_choice"].ToString() == item.Key.ToString()) curclass = " class=\"cur\" ";
FirstUrl.Append("<a href=\"" + oldlink["first_choice"] + "&first_choice=" + item.Key + "\" " + curclass + " >" + item.Value + "</a>");
}
else
{
if (string.IsNullOrEmpty(Request.QueryString["first_choice"])) curclass = " class=\"cur\" ";
FirstUrl.Append("<a href=\"" + oldlink["first_choice"] + "\" " + curclass + " >不限</a>");
}
}
foreach (KeyValuePair<int, string> item in Common.NewShopType())
{
curclass = string.Empty;
if (item.Key != -1)
{
if (Request.QueryString["new_shop_type"] != null && Request.QueryString["new_shop_type"].ToString() == item.Key.ToString()) curclass = " class=\"cur\" ";
NewshopUrl.Append("<a href=\"" + oldlink["new_shop_type"] + "&new_shop_type=" + item.Key + "\" " + curclass + " >" + item.Value + "</a>");
}
else
{
if (string.IsNullOrEmpty(Request.QueryString["new_shop_type"])) curclass = " class=\"cur\" ";
NewshopUrl.Append("<a href=\"" + oldlink["new_shop_type"] + "\" " + curclass + " >不限</a>");
}
}
foreach (KeyValuePair<int, string> item in Common.ShopArea())
{
curclass = string.Empty;
if (item.Key != -1)
{
if (Request.QueryString["shop_area"] != null && Request.QueryString["shop_area"].ToString() == item.Key.ToString())
{
curclass = " class=\"cur\" ";
}
ShopareaUrl.Append("<a href=\"" + oldlink["shop_area"] + "&shop_area=" + item.Key + "\" " + curclass + " >" + item.Value + "</a>");
}
else
{
if (string.IsNullOrEmpty(Request.QueryString["shop_area"]))
{
curclass = " class=\"cur\" ";
}
ShopareaUrl.Append("<a href=\"" + oldlink["shop_area"] + "\" " + curclass + " >不限</a>");
}
}
}
private void BindHouseList()
{
string strGetFields = "*";
string tableName = "Merchant";
string id = "m_id";
string strWhere = "issh=1";
string orderName = "m_id desc";
int recordCount = 0;
int pageCount = 0;
strWhere += GetstrWhere();//搜索条件 生成
IList<MdlMerchant> list = BLLMerchant.GetMdlMerchantListByPager(AspNetPager1.StartRecordIndex / AspNetPager1.PageSize, AspNetPager1.PageSize, ref recordCount, ref pageCount, strGetFields, tableName, id, strWhere, orderName);
string url;
int ic = HttpContext.Current.Request.RawUrl.IndexOf("&page");
if (ic > 0)
{
url = HttpContext.Current.Request.RawUrl.Remove(ic);
}
else
{
url = HttpContext.Current.Request.RawUrl;
}
AspNetPager1.UrlPaging = true;
AspNetPager1.EnableUrlRewriting = true;
AspNetPager1.UrlRewritePattern = url + "&page={0}";
AspNetPager1.RecordCount = recordCount;
AspNetPager1.CustomInfoHTML = "共" + AspNetPager1.RecordCount.ToString() + "条 ";
AspNetPager1.CustomInfoHTML += "当前为:" + AspNetPager1.CurrentPageIndex.ToString() + "/";
AspNetPager1.CustomInfoHTML += AspNetPager1.PageCount.ToString() + "页";
rptHouse.DataSource = list;
rptHouse.DataBind();
}
private string GetstrWhere()
{
StringBuilder strWhere = new StringBuilder();
if (!string.IsNullOrEmpty(Request["bussiness_type1"]))
{
int bus = CommonLibrary.NullToInt(Request.QueryString["bussiness_type1"].ToString());
if (bus > 0)
{
strWhere.Append(" and bussiness_type1=" + bus.ToString());
d_business_type1.Visible = true;
bussiness_type = Common.BussinessType()[bus];
}
}
if (!string.IsNullOrEmpty(Request["new_shop_type"]))
{
int newshop = CommonLibrary.NullToInt(Request.QueryString["new_shop_type"].ToString());
if (newshop > 0)
{
strWhere.Append(" and new_shop_type=" + newshop.ToString());
d_new_shop_type.Visible = true;
new_shop_type = Common.NewShopType()[newshop];
}
}
if (!string.IsNullOrEmpty(Request["shop_area"]))
{
int area = CommonLibrary.NullToInt(Request.QueryString["shop_area"].ToString());
if (area > 0)
{
strWhere.Append(" and shop_area=" + area.ToString());
d_shop_area.Visible = true;
shop_area = Common.ShopArea()[area];
}
}
if (!string.IsNullOrEmpty(Request["first_choice"]))
{
int first = CommonLibrary.NullToInt(Request.QueryString["first_choice"].ToString());
if (first > 0)
{
strWhere.Append(" and first_choice=" + first.ToString());
d_first_property.Visible = true;
first_choice = Common.FirstChoice()[first];
}
}
return strWhere.ToString();
}
private void BindTophouse()
{
string sql = "select top 10 * from merchant where issh=1";
sql += " order by view_count desc";
IList<MdlMerchant> list = BLLMerchant.GetAllMerchantBySql(sql);
if (list.Count > 0)
{
foreach (MdlMerchant info in list)
{
are.Append("<dd><s class=\"rank1\"></s><span><a href='../merchant/" + info.M_id.ToString() + ".html' title='" + info.Brand_name + "' target='_blank'>" + info.Brand_name + "</a></span><i>"+info.View_count.ToString()+"</i></dd>");
}
}
else
{
are.Append("<a>暂无相关信息!</a>");
}
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
BindHouseList();
}
}
|
前台代码index.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="merchant_Index" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<%@ Register Src="../Control/ControlLogin3.ascx" TagName="ControlLogin3" TagPrefix="uc1" %>
<%@ Import Namespace="Logic.Common" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html class="no-js" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>品牌商家搜索_第1页_淄博商业地产网</title>
<meta name="Keywords" content="品牌,品牌商家,全部,商户,开店,主力店,业态,拓展,选址,经营">
<meta name="Description" content="品牌商家搜索,提供百货,酒店,超市,专业店,家居建材,服饰,餐饮,休闲娱乐,专业服务等上万个知名商业品牌查询,可随时了解这些品牌的开店拓展计划、选址标准、发展战略、经营策略等信息。">
<meta name="robots" content="index, follow">
<meta name="googlebot" content="index, follow">
<script type="text/javascript" src="http://data.sydc.sina.com.cn/resource/js/jquery-1.4.1.min.js"></script>
<!--[if IE 6]>
<script type="text/javascript" src="http://www.eju.com/js/global/DD_belatedPNG_0.0.8a-min.js"></script>
<script type="text/javascript">DD_belatedPNG.fix('.logo_wrap_b,.txt_slogan,.ico_tel,.tab_wrap .cur');</script>
<![endif]-->
<link href="../css/list.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="index.css" media="all">
</head>
<body>
<form id="form1" runat="server">
<!-- header -->
<div id="container-wrapper">
<div id="container">
<div id="header">
<div id="header-top"><uc1:ControlLogin3 ID="ControlLogin3_1" runat="server" /></div>
<script type="text/javascript" src="../js/topB.js"></script>
</div>
<div id="breadcrumb_nav" class="row mb10 clearfix">
<div class="breadcrumb">您的位置:<a href="http://www.zbsydc.com" target="_top">淄博商业地产网</a> > <em>找商家</em></div>
<div class="search_con">
<form method="get" action="index.aspx" name="search" id="search_form">
<input class="search_input" value="请输入品牌名称..." name="keyword" id="keyword" maxlength="30" style="color: rgb(153, 153, 153);" onfocus="if(this.value=='请输入品牌名称...')this.value=''" onblur="if(this.value=='')this.value='请输入品牌名称...'" type="text">
<a onclick="clear_keyword()" href="javascript:void(0);" class="search_btn"><s></s>搜索</a>
</form>
</div>
<script type="text/javascript">
function clear_keyword()
{
var keywordinput = document.getElementById('keyword');
if(keywordinput.value=='请输入品牌名称...')
{
keywordinput.value='';
}
$('#search_form').submit();
}
</script>
<script type="text/javascript">
//删除搜索条件
function delCondition(fields)
{
thisURL = document.URL;
thisURL = thisURL.replace(fields+'=','d_'+fields+'=');
document.location.href = thisURL;
}
function listHover() {
$("#house_list .loop").hover(
function () {
$(this).addClass("currentbg");
},
function () {
$(this).removeClass("currentbg");
});
}
listHover();
</script>
</div>
<!--条件筛选-->
<div id="filter_box" class="row mb10 clearfix">
<div class="bar clearfix">
<h6>您已选择:</h6>
<span class="fl" id='d_business_type1' runat="server" visible=false>
<a href="javascript:void(0);" onclick="delCondition('bussiness_type1')" class="s_con"><b><%=bussiness_type %></b></a>
</span>
<span class="fl" id='d_shop_area' runat="server" visible=false>
<a href="javascript:void(0);" onclick="delCondition('shop_area')" class="s_con"><b><%=shop_area %></b></a>
</span>
<span class="fl" id='d_first_property' runat="server" visible=false>
<a href="javascript:void(0);" onclick="delCondition('first_choice')" class="s_con"><b><%=first_choice %></b></a>
</span>
<span class="fl" id='d_new_shop_type' runat="server" visible=false>
<a href="javascript:void(0);" onclick="delCondition('new_shop_type')" class="s_con"><b><%=new_shop_type %></b></a>
</span>
</div>
<div class="flist clearfix">
<dl class="clearfix">
<dt>[业态分类]</dt>
<dd>
<%=BusUrl.ToString() %>
</dd>
</dl>
<dl class="clearfix">
<dt>[面积需求]</dt>
<dd>
<%=ShopareaUrl.ToString()%>
</dd>
</dl>
<dl class="clearfix">
<dt>[开店方式]</dt>
<dd><%=NewshopUrl.ToString()%>
</dd>
</dl>
<dl class="clearfix">
<dt>[首选物业]</dt>
<dd><%=FirstUrl.ToString()%></dd>
</dl>
<dl class="clearfix">
</dl>
</div>
</div>
<!--列表内容-->
<div class="row clearfix">
<div id="list_box" class="first grid720">
<div class="list_top clearfix">
<div class="all_project fl"><a href="#" title="全部项目">全部品牌</a></div>
</div>
<div id="house_list">
<asp:Repeater ID="rptHouse" runat="server">
<ItemTemplate>
<div class="loop clearfix">
<div class="pic fl"><a target="_top" href="/merchant/<%# Eval("m_id")%>">
<img src="/BrandImage/<%# Eval("Brand_image")%>" alt="<%# Eval("Brand_name")%>" height="100" width="150"></a></div>
<div class="text fl">
<div class="tt_bar clearfix">
<div class="tt fl"><a target="_top" title="<%# Eval("Brand_name")%>" href="/merchant/<%# Eval("m_id")%>"><%# Eval("Brand_name")%></a></div>
</div>
<dl class="clearfix addr"><dt class="fl">企业名称:</dt><dd class="fl"><%# Eval("Company_name")%></dd></dl>
<dl class="clearfix addr"><dt class="fl">业态分类:</dt><dd class="fl"><%# Common.BussinessType()[Convert.ToInt32(Eval("Bussiness_type1"))]%></dd></dl>
<dl class="clearfix addr"><dt class="fl">开店方式:</dt><dd class="fl"><%# Common.NewShopType()[Convert.ToInt32(Eval("New_shop_type"))]%></dd></dl>
<dl class="clearfix addr"><dt class="fl">品牌定位:</dt><dd class="fl"><%# Eval("Brand_Position")%></dd></dl>
<dl class="clearfix"><dt class="fl">首选物业:</dt><dd class="fl"><%# Common.FirstChoice()[Convert.ToInt32(Eval("First_Choice"))]%></dd></dl>
</div>
<div class="right_con fl">
<p>联系方式:<em><%# Eval("Contact_info")%></em></p>
<p class="red">面积需求:<em><%# Common.ShopArea()[Convert.ToInt32(Eval("shop_area"))] %></em></p>
<p>合同期限:<em><%# Eval("Contract_period")%></em></p>
<p>店铺总数:<em><%# Eval("Shop_count")%></em></p>
</div>
</div>
<div class="line"></div>
</ItemTemplate>
</asp:Repeater>
</div>
<div class="pager tc">
<div class="pager_info">
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" FirstPageText="【首页】" LastPageText="【末页】" NextPageText="【下一页】" PageSize="10" PrevPageText="【上一页】" ShowCustomInfoSection="Left" ShowInputBox="Always" SubmitButtonText="转到" CustomInfoSectionWidth="60%" OnPageChanged="AspNetPager1_PageChanged">
</webdiyer:AspNetPager>
</div>
</div>
</div>
<div class="grid220" id="rightList">
<div class="same_bd">
<div class="right_title">点击排行</div>
<div class="con con_a clearfix">
<dl class="news_ranklist">
<dt>商家名称<cite>人气</cite></dt>
<%=are %>
</dl>
</div>
</div>
</div>
</div>
<div style="text-align:center;">
<iframe src="../foot.htm" frameborder="0" width="960px" height="90px" scrolling="no"></iframe>
</div>
</div>
</div>
<!-- 引入页尾信息toptray_search.html -->
</form>
</body>
</html>
|


