前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NormalSearch.aspx.cs" Inherits="BookSearch_NormalSearch" %>
<%@ Register src="BookSearchToolBar.ascx" tagname="BookSearchToolBar" tagprefix="uc1" %>
<!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>
<link href="../css/Main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.divmiddlecontent{width:780px;text-align:center; margin:0 auto; border:1px silver solid;}
#btnView{ margin-right:20px;}
.SearchDiv{ width:100%; border-bottom:1px silver solid; margin:2px auto;}
.customer{ float:left; width:25%; border:1px silver solid; height:20px; margin:1px auto; margin-right:4px; padding-left:4px; padding-top:6px;}
#btnSearch{ height:20px;}
#ddlType{ margin-top:4px; }
#txtSearchContent{ margin-top:3px;}
</style>
<link href="../css/Main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="divMain">
<div class="divHeader" >
<uc1:BookSearchToolBar id="BookSearchToolBar1" runat="server" />
</div>
<div class="divContent">
<div class="divmiddlecontent">
<asp:Label CssClass="TableTitle" runat="server" Text="普通查询" id="lblSearchType"></asp:Label>
</div>
<div class="divmiddlecontent" style="text-align:left; padding:5px 0 10px 0;">
<div class="SearchDiv">
<asp:Label runat="server" CssClass="InputTitle customer" Text="请选择文献类别:" id="Label1"></asp:Label>
<asp:RadioButtonList RepeatDirection="Horizontal" CssClass="RadioCheckBox" runat="server" id="rbtnlistType">
<asp:ListItem Value="所有类别" Text="所有类别" Selected="True"></asp:ListItem>
<asp:ListItem Text="中文图书" Value="中文图书"></asp:ListItem>
<asp:ListItem Text="西文图书" Value="西文图书"></asp:ListItem>
<asp:ListItem Text="中文期刊" Value="中文期刊"></asp:ListItem>
<asp:ListItem Text="西文期刊" Value="西文期刊"></asp:ListItem>
</asp:RadioButtonList>
</div>
<div class="SearchDiv">
<asp:Label runat="server" CssClass="InputTitle customer" Text="请输入查询类型:" id="Label2"></asp:Label>
<asp:DropDownList runat="server" id="ddlType">
<asp:ListItem Value="BookName" Text="题名" Selected="True"></asp:ListItem>
<asp:ListItem Text="主题词" Value="Subject"></asp:ListItem>
<asp:ListItem Text="索取号" Value="SearchNO"></asp:ListItem>
<asp:ListItem Text="出版社" Value="PubName"></asp:ListItem>
<asp:ListItem Text="ISBN号" Value="ISBN"></asp:ListItem>
<asp:ListItem Text="丛书名" Value="Series"></asp:ListItem>
</asp:DropDownList>
</div>
<div class="SearchDiv">
<asp:Label runat="server" CssClass="InputTitle customer" Text="请输入查询内容(配合查询类型):" id="Label3"></asp:Label>
<asp:TextBox runat="server" id="txtSearchContent"></asp:TextBox>
<asp:Button runat="server" Text="查询" id="btnSearch" OnClick="btnSearch_Click"></asp:Button>
</div>
<div class="SearchDiv">
<asp:Label runat="server" CssClass="InputTitle customer" Text="请选择查询模式(是否开模糊查询):" id="Label4"></asp:Label>
<asp:RadioButtonList CssClass="RadioCheckBox" RepeatDirection="Horizontal" runat="server" id="rbtnlistPattern">
<asp:listitem Value="0" Selected="True" Text="精确查询"></asp:listitem>
<asp:listitem Value="1" Text="任意匹配"></asp:listitem>
</asp:RadioButtonList>
</div>
</div>
<div class="divmiddlecontent" style="padding:3px 0;">
<asp:Label CssClass="TableTitle" runat="server" Text="查询结果" id="lblSearchResult"></asp:Label>
</div>
<div class="divmiddlecontent" style="padding:3px 0;">
<asp:GridView runat="server" CssClass="GridViewTable" id="gvNormalResult" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" AllowPaging="True" AutoGenerateColumns="False" OnPageIndexChanging="gvNormalResult_PageIndexChanging" OnRowDataBound="gvNormalResult_RowDataBound" PageSize="15">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="bookname" HeaderText="书名" />
<asp:BoundField DataField="bookauthor" HeaderText="作者" />
<asp:BoundField DataField="series" HeaderText="丛书名" />
<asp:BoundField DataField="searchno" HeaderText="索取号" />
<asp:BoundField DataField="bookstate" HeaderText="目前状态" />
</Columns>
</asp:GridView>
<asp:Button runat="server" CssClass="" Text="查看" id="btnView" OnClick="btnView_Click"></asp:Button>
<asp:Button runat="server" Text="预约" id="btnBooking" OnClick="btnBooking_Click"></asp:Button>
</div>
</div>
</div>
</form>
</body>
</html>
后台代码:
public partial class BookSearch_NormalSearch : System.Web.UI.Page
{
protected void btnSearch_Click(object sender, EventArgs e)
{
btnClick();
}
protected void btnClick()//响应按钮单击事件,绑定gv
{
string sqlstr = "";
string sign = "";
if (string.Compare(rbtnlistPattern.SelectedValue, "0") != 0)
{
sign = "%";
}
string bookstyle = "";
string SearchStyle = "";
if (rbtnlistType.SelectedValue != "所有类别")
{
bookstyle = rbtnlistType.SelectedValue.Trim();
SearchStyle = " bookstyle='" + bookstyle + "' and ";
}
string searchcontent = txtSearchContent.Text.Trim() == "" ? "%" : txtSearchContent.Text.Trim();
string searchCondition = " " + ddlType.SelectedValue.Trim() + " like '" + sign + searchcontent + sign + "' order by pubDate desc"; if (SearchStyle != "")
{
sqlstr = "select * from bookinfo where " + SearchStyle + searchCondition;
}
else
{
sqlstr = "select * from bookinfo where " + searchCondition;
}
DBController db = new DBController();
string[] keys = new string[] { "bookid" };
gvNormalResult.DataKeyNames = keys;
db.BandToGV(sqlstr, gvNormalResult);
}
protected void btnBooking_Click(object sender, EventArgs e)
{
if (gvNormalResult.Rows.Count != 0)
{
BookController bb = new BookController();
string par = bb.MessageSendToViewList(gvNormalResult);
string[] bookidArr = par.Split('_');
BookController controller = new BookController();
string userid = User.Identity.Name;
userid = "jsh";
foreach (string bookid in bookidArr)
{
if (bookid != "")
{
controller.BookingBook(userid, bookid);
}
}
Response.Write("<script>javascript:alert('预约成功,收藏、被人预约、被借的图书不能预约');</script>");
}
}
}
这里说我的问题(只贴出有关的后台代码,请帮帮忙)
当我点击“预约”按钮的时候这个页面就变形啦!
据说是css丢失。别人叫我加上window.location.href=window.location.href
但是我原来绑定的数据就丢失啦!我该怎样弄到弹出对话框,之后页面保持原来的样子啊?
可以加我qq聊 573993835 说明是"csdn"
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NormalSearch.aspx.cs" Inherits="BookSearch_NormalSearch" %>
<%@ Register src="BookSearchToolBar.ascx" tagname="BookSearchToolBar" tagprefix="uc1" %>
<!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>
<link href="../css/Main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.divmiddlecontent{width:780px;text-align:center; margin:0 auto; border:1px silver solid;}
#btnView{ margin-right:20px;}
.SearchDiv{ width:100%; border-bottom:1px silver solid; margin:2px auto;}
.customer{ float:left; width:25%; border:1px silver solid; height:20px; margin:1px auto; margin-right:4px; padding-left:4px; padding-top:6px;}
#btnSearch{ height:20px;}
#ddlType{ margin-top:4px; }
#txtSearchContent{ margin-top:3px;}
</style>
<link href="../css/Main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="divMain">
<div class="divHeader" >
<uc1:BookSearchToolBar id="BookSearchToolBar1" runat="server" />
</div>
<div class="divContent">
<div class="divmiddlecontent">
<asp:Label CssClass="TableTitle" runat="server" Text="普通查询" id="lblSearchType"></asp:Label>
</div>
<div class="divmiddlecontent" style="text-align:left; padding:5px 0 10px 0;">
<div class="SearchDiv">
<asp:Label runat="server" CssClass="InputTitle customer" Text="请选择文献类别:" id="Label1"></asp:Label>
<asp:RadioButtonList RepeatDirection="Horizontal" CssClass="RadioCheckBox" runat="server" id="rbtnlistType">
<asp:ListItem Value="所有类别" Text="所有类别" Selected="True"></asp:ListItem>
<asp:ListItem Text="中文图书" Value="中文图书"></asp:ListItem>
<asp:ListItem Text="西文图书" Value="西文图书"></asp:ListItem>
<asp:ListItem Text="中文期刊" Value="中文期刊"></asp:ListItem>
<asp:ListItem Text="西文期刊" Value="西文期刊"></asp:ListItem>
</asp:RadioButtonList>
</div>
<div class="SearchDiv">
<asp:Label runat="server" CssClass="InputTitle customer" Text="请输入查询类型:" id="Label2"></asp:Label>
<asp:DropDownList runat="server" id="ddlType">
<asp:ListItem Value="BookName" Text="题名" Selected="True"></asp:ListItem>
<asp:ListItem Text="主题词" Value="Subject"></asp:ListItem>
<asp:ListItem Text="索取号" Value="SearchNO"></asp:ListItem>
<asp:ListItem Text="出版社" Value="PubName"></asp:ListItem>
<asp:ListItem Text="ISBN号" Value="ISBN"></asp:ListItem>
<asp:ListItem Text="丛书名" Value="Series"></asp:ListItem>
</asp:DropDownList>
</div>
<div class="SearchDiv">
<asp:Label runat="server" CssClass="InputTitle customer" Text="请输入查询内容(配合查询类型):" id="Label3"></asp:Label>
<asp:TextBox runat="server" id="txtSearchContent"></asp:TextBox>
<asp:Button runat="server" Text="查询" id="btnSearch" OnClick="btnSearch_Click"></asp:Button>
</div>
<div class="SearchDiv">
<asp:Label runat="server" CssClass="InputTitle customer" Text="请选择查询模式(是否开模糊查询):" id="Label4"></asp:Label>
<asp:RadioButtonList CssClass="RadioCheckBox" RepeatDirection="Horizontal" runat="server" id="rbtnlistPattern">
<asp:listitem Value="0" Selected="True" Text="精确查询"></asp:listitem>
<asp:listitem Value="1" Text="任意匹配"></asp:listitem>
</asp:RadioButtonList>
</div>
</div>
<div class="divmiddlecontent" style="padding:3px 0;">
<asp:Label CssClass="TableTitle" runat="server" Text="查询结果" id="lblSearchResult"></asp:Label>
</div>
<div class="divmiddlecontent" style="padding:3px 0;">
<asp:GridView runat="server" CssClass="GridViewTable" id="gvNormalResult" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" AllowPaging="True" AutoGenerateColumns="False" OnPageIndexChanging="gvNormalResult_PageIndexChanging" OnRowDataBound="gvNormalResult_RowDataBound" PageSize="15">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="bookname" HeaderText="书名" />
<asp:BoundField DataField="bookauthor" HeaderText="作者" />
<asp:BoundField DataField="series" HeaderText="丛书名" />
<asp:BoundField DataField="searchno" HeaderText="索取号" />
<asp:BoundField DataField="bookstate" HeaderText="目前状态" />
</Columns>
</asp:GridView>
<asp:Button runat="server" CssClass="" Text="查看" id="btnView" OnClick="btnView_Click"></asp:Button>
<asp:Button runat="server" Text="预约" id="btnBooking" OnClick="btnBooking_Click"></asp:Button>
</div>
</div>
</div>
</form>
</body>
</html>
后台代码:
public partial class BookSearch_NormalSearch : System.Web.UI.Page
{
protected void btnSearch_Click(object sender, EventArgs e)
{
btnClick();
}
protected void btnClick()//响应按钮单击事件,绑定gv
{
string sqlstr = "";
string sign = "";
if (string.Compare(rbtnlistPattern.SelectedValue, "0") != 0)
{
sign = "%";
}
string bookstyle = "";
string SearchStyle = "";
if (rbtnlistType.SelectedValue != "所有类别")
{
bookstyle = rbtnlistType.SelectedValue.Trim();
SearchStyle = " bookstyle='" + bookstyle + "' and ";
}
string searchcontent = txtSearchContent.Text.Trim() == "" ? "%" : txtSearchContent.Text.Trim();
string searchCondition = " " + ddlType.SelectedValue.Trim() + " like '" + sign + searchcontent + sign + "' order by pubDate desc"; if (SearchStyle != "")
{
sqlstr = "select * from bookinfo where " + SearchStyle + searchCondition;
}
else
{
sqlstr = "select * from bookinfo where " + searchCondition;
}
DBController db = new DBController();
string[] keys = new string[] { "bookid" };
gvNormalResult.DataKeyNames = keys;
db.BandToGV(sqlstr, gvNormalResult);
}
protected void btnBooking_Click(object sender, EventArgs e)
{
if (gvNormalResult.Rows.Count != 0)
{
BookController bb = new BookController();
string par = bb.MessageSendToViewList(gvNormalResult);
string[] bookidArr = par.Split('_');
BookController controller = new BookController();
string userid = User.Identity.Name;
userid = "jsh";
foreach (string bookid in bookidArr)
{
if (bookid != "")
{
controller.BookingBook(userid, bookid);
}
}
Response.Write("<script>javascript:alert('预约成功,收藏、被人预约、被借的图书不能预约');</script>");
}
}
}
这里说我的问题(只贴出有关的后台代码,请帮帮忙)
当我点击“预约”按钮的时候这个页面就变形啦!
据说是css丢失。别人叫我加上window.location.href=window.location.href
但是我原来绑定的数据就丢失啦!我该怎样弄到弹出对话框,之后页面保持原来的样子啊?
可以加我qq聊 573993835 说明是"csdn"
public class MessageBox
{
private MessageBox()
{
} /// <summary>
/// 显示消息提示对话框
/// </summary>
/// <param name="page">当前页面指针,一般为this</param>
/// <param name="msg">提示信息</param>
public static void Show(System.Web.UI.Page page, string msg)
{
page.RegisterStartupScript("message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
} /// <summary>
/// 控件点击 消息确认提示框
/// </summary>
/// <param name="page">当前页面指针,一般为this</param>
/// <param name="msg">提示信息</param>
public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string msg)
{
//Control.Attributes.Add("onClick","if (!window.confirm('"+msg+"')){return false;}");
Control.Attributes.Add("onclick", "return confirm('" + msg + "');");
} /// <summary>
/// 显示消息提示对话框,并进行页面跳转
/// </summary>
/// <param name="page">当前页面指针,一般为this</param>
/// <param name="msg">提示信息</param>
/// <param name="url">跳转的目标URL</param>
public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url)
{
StringBuilder Builder = new StringBuilder();
Builder.Append("<script language='javascript' defer>");
Builder.AppendFormat("alert('{0}');", msg);
Builder.AppendFormat("location.href='{0}'", url);
Builder.Append("</script>");
page.RegisterStartupScript("message", Builder.ToString()); } public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url, bool top)
{
StringBuilder Builder = new StringBuilder();
Builder.Append("<script language='javascript' defer>");
Builder.AppendFormat("alert('{0}');", msg);
if (top == true)
{
Builder.AppendFormat("top.location.href='{0}'", url);
}
else
{
Builder.AppendFormat("location.href='{0}'", url);
}
Builder.Append("</script>");
page.RegisterStartupScript("message", Builder.ToString()); }
/// <summary>
/// 输出自定义脚本信息
/// </summary>
/// <param name="page">当前页面指针,一般为this</param>
/// <param name="script">输出脚本</param>
public static void ResponseScript(System.Web.UI.Page page, string script)
{
page.RegisterStartupScript("message", "<script language='javascript' defer>" + script + "</script>");
}
}
我用这样解决了问题。谢谢大家啊。