Search within my site asp.net
Search within my site
I have created a search box that is working fine, but I have a problem whereby I search a word and it appears everything on the database. What I really want it to do is to search for a specific word (title and content).Well on the 1st page(webform1.aspx) it works fine, but on the second page(entry.aspx) When i click a link after searching, it shows everything on the database and i don't want that to happen
DATABASE
DB name : mysearch
DB table : Blog
blogId
blogTitle
blogContents
webform1.aspx
<form id="form1" runat="server">
<div>
<h1>search for something, man!</h1>
<p><asp:TextBox runat="server" ID="txtSearch" Text="search for something"></asp:TextBox></p>
<p><asp:Button runat="server" ID="btnSubmit" Text="Search" OnClick="btnSubmit_Click" /></p>
<asp:ListView runat="server" ID="lv">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<a href="<%# ResolveClientUrl("~/entry.aspx?id=" + Eval("BlogTitle").ToString()) %>"><%# Server.HtmlEncode(Eval("BlogTitle").ToString())%></a>
<%#Eval("BlogContents")%>
</ItemTemplate>
</asp:ListView>
</div>
</form>
Webform1.aspx.cs
protected void btnSubmit_Click(object sender, EventArgs e)
{
BlogDBDataContext db = new BlogDBDataContext();
dynamic q = from b in db.Blogs
where b.BlogContents.Contains(txtSearch.Text.Trim()) | b.BlogTitle.Contains(txtSearch.Text.Trim())
select b;
lv.DataSource = q;
lv.DataBind();
}
Entry.aspx
<form id="form1" runat="server">
<div>
<asp:ListView runat="server" ID="lv">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="itemPlaceHolder"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<h1><%#Eval ("BlogTitle") %></h1>
<div>
<%#Eval("BlogContents")%>
</div>
</ItemTemplate>
</asp:ListView>
</div>
</form>
Entry.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
BlogDBDataContext db = new BlogDBDataContext();
dynamic q = from b in db.Blogs
select b;
lv.DataSource = q;
lv.DataBind();
}
i need help guys ASP please.
Guys the problem its on the entry page whenever i click a link on webform1 page after searching, it shows everything and i'm confused why is it like that.