我写信是为了寻求在asp.net webform中实现多标准搜索功能的帮助 我是asp.net的新手用户并使用示例C#代码实现了以下vb代码,但我无法显示任何输出。
非常感谢任何帮助。感谢您的时间。
ASPX
<div class = "hideSkiplink">
<asp:Label ID="Label1" runat="server" Text="Name" ForeColor="White"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Cusip/Isin" ForeColor="White"> </asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" OnClick = "btnSearch_Click" />
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:bwic testConnectionString %>"
SelectCommand="SELECT [Deal_name], [Cusip], [Isin], [Original_size], [Price],_
[Price_recieved], [Deal_type], [Price_type], [Date] FROM [Price]"> </asp:SqlDataSource>
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
aspx.vb
Imports System.Data
Imports System.Web.Services
Imports System.Configuration
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
SqlDataSource1.SelectCommand = "select * from Price where Deal_name like '%" + TextBox1.Text + "%' or Cusip and Isin like '%" + TextBox2.Text + "%'"
SqlDataSource1.DataBind()
End Sub
End Class
答案 0 :(得分:1)
您希望分别在Cusip
和Isin
上同时执行此操作:
SqlDataSource1.SelectCommand = _
"SELECT * FROM Price " + _
"WHERE Deal_name like '%" + TextBox1.Text + _
"%' AND (Cusip like '%" + TextBox2.Text +
"%' OR Isin like '%" + TextBox2.Text + "%')"
这将选择Deal_name
匹配TextBox1
和Cusip
或Isin
匹配TextBox2
的记录。如果这不是你想要的,请澄清。
编辑:
您的GridView
需要在其上设置DataSourceID
,否则它不知道数据的来源。请看下面taken from here下面的示例,该示例不需要单击按钮即可进行绑定。
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$Connectionstrings:ERPConnectionString%>"
SelectCommand="SELECT * FROM AccountsTable">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" DataSourceID="SqlDataSource1"
AutoGenerateColumns="true" runat="server">
</asp:GridView>