如题
这个是我用的存储过程:
CREATE PROCEDURE dbo.Searchresult
@bookname nvarchar(50)=null,
@author nvarchar(50)=null,
@press nvarchar(50)=null,
@ISBN nvarchar(50)=null
AS
select *
from Product
where Product_name like '%'+isnull(@bookname,'')+'%'
and Author like '%'+isnull(@author,'')+'%'
and Press like '%'+isnull(@press,'')+'%'
and ISBN like '%'+isnull(@ISBN,'')+'%'
GO这个是.aspx和后台代码
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>搜索结果</title>
</head>
<body>
<form id="form1" runat="server">
<table border="0" cellpadding="0" cellspacing="0" style="width: 587px" align=center>
<tr>
<td colspan="3">
<uc1:Top ID="Top1" runat="server" />
</td>
</tr>
<tr>
<td colspan="3">
<img height="5" src="img/spacer.gif" /></td>
</tr>
<tr>
<td colspan="3">
<table border="0" cellpadding="0" cellspacing="0" style="font-size: 11pt; width: 833px">
<tr>
<td colspan="11">
<hr style="border-right: #437ac5 1px solid; border-top: #437ac5 1px solid; border-left: #437ac5 1px solid;
border-bottom: #437ac5 1px solid" />
<img src="UserControls/img/spacer.gif" /></td>
</tr>
<tr>
<td style="width: 3px">
<img height="1" src="img/spacer.gif" width="20" /></td>
<td style="width: 51px">
按书名:</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Height="13px" Width="108px"></asp:TextBox></td>
<td>
按作者:</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Height="13px" Width="108px"></asp:TextBox></td>
<td>
按出版社:</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" Height="13px" Width="108px"></asp:TextBox></td>
<td>
按ISBN:</td>
<td style="width: 129px">
<asp:TextBox ID="TextBox4" runat="server" Height="13px" Width="108px"></asp:TextBox></td>
<td><asp:ImageButton ID="search" runat="server" ImageUrl="~/img/ss.gif" />
</td>
<td style="width: 2px">
<img height="1" src="UserControls/img/spacer.gif" width="20" /></td>
</tr>
<tr>
<td colspan="11">
<hr style="border-right: #437ac5 1px solid; border-top: #437ac5 1px solid; border-left: #437ac5 1px solid;
border-bottom: #437ac5 1px solid" />
<img src="UserControls/img/spacer.gif" /></td>
</tr>
</table>
<img src="img/spacer.gif" /></td>
</tr>
<tr>
<td colspan="3">
<img height="5" src="img/spacer.gif" /></td>
</tr>
<tr>
<td colspan="3">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="833px">
</asp:GridView>
<img src="img/spacer.gif" /></td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:boyabookshopConnectionString %>" SelectCommand="Searchresult" SelectCommandType="StoredProcedure" DataSourceMode="DataReader">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="bookname"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="False" />
<asp:ControlParameter ControlID="TextBox2" Name="author" PropertyName="Text"
Type="String" ConvertEmptyStringToNull="False" />
<asp:ControlParameter ControlID="TextBox3" Name="press" PropertyName="Text" Type="String" ConvertEmptyStringToNull="False" />
<asp:ControlParameter ControlID="TextBox4" Name="ISBN" PropertyName="Text" Type="String" ConvertEmptyStringToNull="False" />
</SelectParameters> </asp:SqlDataSource>
</form>
</body>
</html>以下是后台代码:
Partial Class searchresult
Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not TextBox1.Text = "" And TextBox2.Text = "" And TextBox3.Text = "" And TextBox4.Text = "" Then
GridView1.DataSource = SqlDataSource1
GridView1.DataBind()
End If
End Sub Protected Sub search_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles search.Click
If Not TextBox1.Text = "" And TextBox2.Text = "" And TextBox3.Text = "" And TextBox4.Text = "" Then
GridView1.DataSource = SqlDataSource1
GridView1.DataBind()
End If
End Sub
End Class
这个是我用的存储过程:
CREATE PROCEDURE dbo.Searchresult
@bookname nvarchar(50)=null,
@author nvarchar(50)=null,
@press nvarchar(50)=null,
@ISBN nvarchar(50)=null
AS
select *
from Product
where Product_name like '%'+isnull(@bookname,'')+'%'
and Author like '%'+isnull(@author,'')+'%'
and Press like '%'+isnull(@press,'')+'%'
and ISBN like '%'+isnull(@ISBN,'')+'%'
GO这个是.aspx和后台代码
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>搜索结果</title>
</head>
<body>
<form id="form1" runat="server">
<table border="0" cellpadding="0" cellspacing="0" style="width: 587px" align=center>
<tr>
<td colspan="3">
<uc1:Top ID="Top1" runat="server" />
</td>
</tr>
<tr>
<td colspan="3">
<img height="5" src="img/spacer.gif" /></td>
</tr>
<tr>
<td colspan="3">
<table border="0" cellpadding="0" cellspacing="0" style="font-size: 11pt; width: 833px">
<tr>
<td colspan="11">
<hr style="border-right: #437ac5 1px solid; border-top: #437ac5 1px solid; border-left: #437ac5 1px solid;
border-bottom: #437ac5 1px solid" />
<img src="UserControls/img/spacer.gif" /></td>
</tr>
<tr>
<td style="width: 3px">
<img height="1" src="img/spacer.gif" width="20" /></td>
<td style="width: 51px">
按书名:</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" Height="13px" Width="108px"></asp:TextBox></td>
<td>
按作者:</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Height="13px" Width="108px"></asp:TextBox></td>
<td>
按出版社:</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" Height="13px" Width="108px"></asp:TextBox></td>
<td>
按ISBN:</td>
<td style="width: 129px">
<asp:TextBox ID="TextBox4" runat="server" Height="13px" Width="108px"></asp:TextBox></td>
<td><asp:ImageButton ID="search" runat="server" ImageUrl="~/img/ss.gif" />
</td>
<td style="width: 2px">
<img height="1" src="UserControls/img/spacer.gif" width="20" /></td>
</tr>
<tr>
<td colspan="11">
<hr style="border-right: #437ac5 1px solid; border-top: #437ac5 1px solid; border-left: #437ac5 1px solid;
border-bottom: #437ac5 1px solid" />
<img src="UserControls/img/spacer.gif" /></td>
</tr>
</table>
<img src="img/spacer.gif" /></td>
</tr>
<tr>
<td colspan="3">
<img height="5" src="img/spacer.gif" /></td>
</tr>
<tr>
<td colspan="3">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="833px">
</asp:GridView>
<img src="img/spacer.gif" /></td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:boyabookshopConnectionString %>" SelectCommand="Searchresult" SelectCommandType="StoredProcedure" DataSourceMode="DataReader">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="bookname"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="False" />
<asp:ControlParameter ControlID="TextBox2" Name="author" PropertyName="Text"
Type="String" ConvertEmptyStringToNull="False" />
<asp:ControlParameter ControlID="TextBox3" Name="press" PropertyName="Text" Type="String" ConvertEmptyStringToNull="False" />
<asp:ControlParameter ControlID="TextBox4" Name="ISBN" PropertyName="Text" Type="String" ConvertEmptyStringToNull="False" />
</SelectParameters> </asp:SqlDataSource>
</form>
</body>
</html>以下是后台代码:
Partial Class searchresult
Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not TextBox1.Text = "" And TextBox2.Text = "" And TextBox3.Text = "" And TextBox4.Text = "" Then
GridView1.DataSource = SqlDataSource1
GridView1.DataBind()
End If
End Sub Protected Sub search_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles search.Click
If Not TextBox1.Text = "" And TextBox2.Text = "" And TextBox3.Text = "" And TextBox4.Text = "" Then
GridView1.DataSource = SqlDataSource1
GridView1.DataBind()
End If
End Sub
End Class
解决方案 »
- javascript的疑惑,绑定select控件的问题
- asp.net程序项目开发流程?
- asp.net内置编辑,删除,求后台代码!!!
- 大量图片的存储
- 高手请进,请教个简单问题
- 发送邮件错误
- 这里有没有java和.net都会的人啊
- 请教:关于showModalDialog的问题——难道Dialog只在第一次打开时执行后台?
- 向你推荐一个最好的ASP.NET空间
- int count = Convert.ToInt32(CommonLib.AccessHelper.ExecuteScalar(sql));语句怎么改才正确
- 我出的招聘面谈试题公开,大家来看看?
- 如何通过代码把Textbox的text绑定到存储过程中的参数值
not 还是不notIf TextBox1.Text <> "" And TextBox2.Text <> "" And TextBox3.Text <> "" And TextBox4.Text <> "" Then
四个都不为空