BookList.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BookList.aspx.cs" Inherits="BookList" %>
<!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>
<style type="text/css">
<!--
.STYLE2 {color: #000000}
.nor {
font-size: 12px;
color: #666666;
}
-->
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" OnItemCommand="DataList1_ItemCommand" OnSelectedIndexChanged="DataList1_SelectedIndexChanged">
<ItemTemplate>
<table align="center" bgcolor="#cccccc" border="0" cellpadding="0" cellspacing="1"
width="444">
<!--DWLayoutTable-->
<tr>
<td bgcolor="#ffffff" rowspan="5" valign="top" width="128">
<!--DWLayoutEmptyCell-->
<asp:Image ID="Image1" runat="server" Height="153px" Width="119px" ImageUrl='<%#Eval("bookImgPath") %>'/></td>
<td align="right" bgcolor="#ffffff" class="nor" height="30" valign="middle" width="72">
编号:</td>
<td align="left" bgcolor="#ffffff" class="nor" valign="middle" width="240">
<!--DWLayoutEmptyCell-->
<asp:Label ID="Label1" runat="server" Text='<%#Eval("bookID") %>'></asp:Label></td>
</tr>
<tr>
<td align="right" bgcolor="#ffffff" class="nor" height="30" valign="middle">
书名:</td>
<td align="left" bgcolor="#ffffff" class="nor" valign="middle">
<!--DWLayoutEmptyCell-->
<asp:Label ID="Label2" runat="server" Text='<%#Eval("bookName") %>'></asp:Label></td>
</tr>
<tr>
<td align="right" bgcolor="#ffffff" class="nor" height="34" valign="middle">
作者:</td>
<td align="left" bgcolor="#ffffff" class="nor" valign="middle">
<!--DWLayoutEmptyCell-->
<asp:Label ID="Label3" runat="server" Text='<%#Eval("bookAuthor") %>'></asp:Label></td>
</tr>
<tr>
<td align="right" bgcolor="#ffffff" class="nor" valign="middle" style="height: 28px">
出版社:</td>
<td align="left" bgcolor="#ffffff" class="nor" valign="middle" style="height: 28px">
<!--DWLayoutEmptyCell-->
<asp:Label ID="Label4" runat="server" Text='<%#Eval("bookPress") %>'></asp:Label></td>
</tr>
<tr>
<td align="right" bgcolor="#ffffff" class="nor" height="33" valign="middle">
单价:</td>
<td align="left" bgcolor="#ffffff" class="nor" valign="middle">
<!--DWLayoutEmptyCell-->
<asp:Label ID="Label5" runat="server" Text='<%#Eval("bookPrice") %>'></asp:Label></td>
</tr>
<tr>
<td align="center" bgcolor="#ffffff" class="nor" colspan="3" height="62" valign="middle">
<!--DWLayoutEmptyCell-->
<asp:Label ID="Label6" runat="server" Text='<%#Eval("bookDesc") %>'></asp:Label> </td>
</tr>
<tr>
<td align="center" bgcolor="#ffffff" colspan="3" height="28" valign="middle">
<!--DWLayoutEmptyCell-->
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Select" OnClick="LinkButton1_Click">购买</asp:LinkButton> <asp:LinkButton
ID="LinkButton2" runat="server" CommandName="Delete">收藏</asp:LinkButton></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<asp:TextBox ID="TextBox2" runat="server" Style="z-index: 107; left: 517px; position: absolute;
top: 491px" Width="378px"></asp:TextBox>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"
Style="z-index: 101; left: 666px; position: absolute; top: 217px" Width="126px">
</asp:DropDownList>
<asp:Label ID="Label8" runat="server" Style="z-index: 102; left: 570px; position: absolute;
top: 218px" Text="出版社:" Width="76px"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Style="z-index: 103; left: 515px; position: absolute;
top: 430px" Visible="False">select * from bookInfo</asp:TextBox>
<asp:Label ID="Label7" runat="server" Style="z-index: 104; left: 572px; position: absolute;
top: 257px" Text="价格" Width="82px"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" Style="z-index: 105; left: 670px;
position: absolute; top: 256px" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="z-index: 106;
left: 661px; position: absolute; top: 333px" Text="查询" />
</div>
</form>
</body>
</html>
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.Data.SqlClient;
public partial class BookList : System.Web.UI.Page
{
string sql1 = "select * from bookInfo where bookPrice>0";
protected void Page_Load(object sender, EventArgs e)
{
this.DataList1.DataSource = this.GetBookInfo();
this.DataList1.DataBind();
if (!IsPostBack)
{
ArrayList arr1 = new ArrayList();
arr1.Add("所有");
arr1.Add("20以下");
arr1.Add("20-30");
arr1.Add("30-40");
arr1.Add("40以上");
DropDownList1.DataSource = arr1;
DropDownList1.DataBind();
ArrayList arr2 = new ArrayList();
arr2.Add("所有");
arr2.Add("电子工业出版社");
arr2.Add("人民邮电出版社");
arr2.Add("清华教育出版社");
arr2.Add("北京大学出版社");
arr2.Add("四川水利出版社");
DropDownList2.DataSource = arr2;
DropDownList2.DataBind();
}
}
private DataTable GetBookInfo()
{
sql1 = TextBox1.Text + TextBox2.Text;
Response.Write(sql1);
SqlConnection scon = new SqlConnection(@"Data Source=MICROSOF-3A2289;User ID=sa;Database=myDatabase");
SqlDataAdapter sda = new SqlDataAdapter(sql1, scon);
DataTable dt = new DataTable();
sda.Fill(dt);
sda.Dispose();
scon.Dispose();
return dt;
}
protected void LinkButton1_Click(object sender, EventArgs e) {
//Response.Write("ok..........");
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) {
Response.Write(e.Item.ItemIndex);
Response.Write(e.CommandName);
Response.Write((e.Item.FindControl("Label1") as Label).Text);
}
protected void DataList1_SelectedIndexChanged(object sender, EventArgs e) {
// Response.Write("select");
}
protected void Button1_Click(object sender, EventArgs e)
{
// Response.Write(TextBox1.Text);
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList2.SelectedValue == "所有")
{
TextBox2.Text = "and 1=1";
}
else
{
TextBox2.Text = " and bookPress='" + DropDownList2.SelectedValue + "'";
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (DropDownList1.SelectedValue)
{
case "所有":
TextBox1.Text = "select * from bookInfo where bookPrice>0";
break;
case "20以下":
TextBox1.Text = "select * from bookInfo where bookPrice<=20";
break;
case "20-30":
TextBox1.Text = "select * from bookInfo where bookPrice>20 and bookPrice<=30" ;
break;
case "30-40":
TextBox1.Text = "select * from bookInfo where bookPrice>30 and bookPrice<=40";
break;
default:
TextBox1.Text = "select * from bookInfo where bookPrice>40";
break;
}
}
}