专题图编号:ylbtechASPNET
1,功能描述 |
搜索查询,如何保存查找条件。
2,技术与环境 |
3,数据库设计 |
4,功能截图 |
4.1,前台
4.1.1
4.1.2
5,代码分析 |
解决方案属性图
5.1 方案一
DropSearchDemo.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DropSearchDemo2.aspx.cs" Inherits="DropSearch_DropSearchDemo2" %>
<!
DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns="http://www.w3.org/1999/xhtml">
<
head
runat="server">
<
title
></
title
>
<
script
type="text/javascript" src="jquery-1.3.2.min.js"></
script
>
<
script
type="text/javascript">
function search(keyword, type) {
var keyword = $("#" + keyword).val();
var type = $("#" + type).val();
window.location.href = "?keyword=" + myescape(keyword) + "&type=" + type;
}
function myescape(str) {
return escape(str).replace("+", "%2B");
}
</
script
>
</
head
>
<
body
>
<
form
action="DropSearchDemo2.aspx" method="get">
<
table
border="1" width="600px">
<
tr
>
<
td
>
商品索索:
</
td
>
<
td
>
<
select
id="type" name="type">
<
option
value="1">图片</
option
>
<
option
value="2">新闻</
option
>
<
option
value="3">娱乐</
option
>
</
select
>
</
td
>
<
td
>
<
input
id="keyword" runat="server" name="keyword" type="text" autocomplete="off"
onkeydown="javascript:if(event.keyCode==13){search('keyword','type');return false;}" />
</
td
>
<
td
>
<
input
type="button" value="Search" onclick="search('keyword','type')" />
</
td
>
</
tr
>
</
table
>
<!--begion 设默认选择类型-->
<%--<
script
>
$("#type").val(2);
</
script
>--%>
<!--end 设默认选择类型-->
<
asp:Literal
ID="LSelectDefault" runat="server"></
asp:Literal
>
</
form
>
</
body
>
</
html
>
|
DropSearchDemo.aspx.cs
using
System;
public
partial
class
DropSearch_DropSearchDemo : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!
string
.IsNullOrEmpty(Request[
"type"
]))
//分类,存在则设默认
{
string
type=Request[
"type"
];
LSelectDefault.Text =
"<script> document.getElementById('type').value = "
+type+
";</script>"
;
}
if
(!
string
.IsNullOrEmpty(Request[
"keyword"
]))
////关键字,存在则设默认
{
keyword.Value = Request[
"keyword"
];
}
}
}
|
5.2,方案二
DropSearchDemo2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DropSearchDemo2.aspx.cs" Inherits="DropSearch_DropSearchDemo2" %>
<!
DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns="http://www.w3.org/1999/xhtml">
<
head
runat="server">
<
title
></
title
>
<
script
type="text/javascript" src="jquery-1.3.2.min.js"></
script
>
<
script
type="text/javascript">
function search(keyword, type) {
var keyword = $("#" + keyword).val();
var type = $("#" + type).val();
window.location.href = "?keyword=" + myescape(keyword) + "&type=" + type;
}
function myescape(str) {
return escape(str).replace("+", "%2B");
}
</
script
>
</
head
>
<
body
>
<
form
action="DropSearchDemo2.aspx" method="get">
<
table
border="1" width="600px">
<
tr
>
<
td
>
商品索索:
</
td
>
<
td
>
<
select
id="type" name="type">
<
option
value="1">图片</
option
>
<
option
value="2">新闻</
option
>
<
option
value="3">娱乐</
option
>
</
select
>
</
td
>
<
td
>
<
input
id="keyword" runat="server" name="keyword" type="text" autocomplete="off"
onkeydown="javascript:if(event.keyCode==13){search('keyword','type');return false;}" />
</
td
>
<
td
>
<
input
type="button" value="Search" onclick="search('keyword','type')" />
</
td
>
</
tr
>
</
table
>
<!--begion 设默认选择类型-->
<%--<
script
>
$("#type").val(2);
</
script
>--%>
<!--end 设默认选择类型-->
<
asp:Literal
ID="LSelectDefault" runat="server"></
asp:Literal
>
</
form
>
</
body
>
</
html
>
|
DropSearchDemo2.aspx.cs
using
System;
public
partial
class
DropSearch_DropSearchDemo2 : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!
string
.IsNullOrEmpty(Request[
"type"
]))
//分类,存在则设默认
{
string
type = Request[
"type"
];
LSelectDefault.Text =
"<script> $('#type').val("
+type+
");</script>"
;
}
if
(!
string
.IsNullOrEmpty(Request[
"keyword"
]))
////关键字,存在则设默认
{
keyword.Value = Request[
"keyword"
];
}
}
}
|
6,示例|讲解案例下载 |
博客园讲解: http://ylbtech.cnblogs.com/
百度文库开发文档: http://passport.baidu.com/?business&aid=6&un=ylbtech#7
谷歌开源代码下载: http://code.google.com/p/ylbtechopensource/downloads/list
请单击“搜索框设默认DropDown”
本文转自ylbtech博客园博客,原文链接:http://www.cnblogs.com/ylbtech/archive/2012/09/05/2670755.html,如需转载请自行联系原作者