Last post Feb 23, 2015 09:44 AM by Rion Williams
Feb 23, 2015 08:10 AM|dzakyalfajr|LINK
hello guys, I want to make search box in my website, and I really dont know how.. the result will be displayed in datalist where datalist datakeyfield = search inquiry.
I watched some video in youtube that shows tutorial on how to make search box using SqlDataSource, and I'm not familiar with it. Can you guys show me how to do the same using AccessDataSource?
Thank you in advance..
Feb 23, 2015 09:44 AM|Rion Williams|LINK
All of the major datasource elements (e.g SqlDataSource, AccessDataSource, etc.) should function quite similarly, so the tutorials that you came across earlier should still be fairly applicable.
Basically, if you have your Datalist being bound to your AccessDataSource, what you'll want to do is actually update the SelectCommand, which is used to populate your list, with your specific search query :
<form id="form1" runat="server">
<!-- Define your Controls -->
<asp:TextBox ID="Search" runat="server"></asp:TextBox>
<asp:Button ID="SearchButton" runat="server" Text="Search"/>
<asp:DataList ID="YourDataList" runat="server" DataSourceID="YourAccessDataSource"></asp:DataList>
<asp:AccessDataSource ID="YourAccessDataSource" runat="server"/>
Along with :
Public Class Example
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Protected Sub SearchButton_Click(sender As Object, e As EventArgs) Handles SearchButton.Click
' When your search button is clicked, build your query '
YourAccessDataSource.SelectCommand = "SELECT * FROM YourTable WHERE YourColumn LIKE @SearchTerm"
' Add your searchterm as a parameter '
YourAccessDataSource.SelectParameters.Add("@SearchTerm", "*" + Search.Text + "*")
' Bind this query to your DataList '
This is obviously a very simplified example, but it should hopefully point you in the right direction.