ASP.net:查找框设默认
专题图编号: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://ylbtech.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |
| 最终目标 |
“代码的国际化标准示例 ylb,tech”,最大程度地规范软件编程开发统一,优质, 高效,易学,为建设软件强国(中国)而努力。
浙公网安备 33010602011771号