Bunu Demek istemiştiniz Uygulama sitesi — Asp Net


Default.aspx
[code lang=”html”]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtKeyword" runat="server" Width="320px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Ara" Width="47px" />
<p><asp:Literal ID="ltlResultText" runat="server"></asp:Literal></p>
<asp:Repeater ID="rptResults" runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:HyperLink ID="hypTitle" runat="server" NavigateUrl="#" Text='<%# Eval("Baslik") %>’></asp:HyperLink>
</td>
</tr>
<tr>
<td>
<asp:Literal ID="ltlDescription" runat="server" Text='<%# Eval("Aciklama") %>’></asp:Literal>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
[/code]
Default.aspx.cs
[code lang=”csharp”]using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Linq;
using System.Web;//www.gorselprogramlama.com
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public void Search(string keyword)
{
SqlConnection cnn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Data;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Select * From Konular Where Baslik Like ‘%’ + @Kelime+ ‘%’";
cmd.Parameters.AddWithValue("@Kelime", keyword);
cmd.Connection = cnn;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt != null && dt.Rows.Count > 0)
{
rptResults.DataSource = dt;
rptResults.DataBind();
}
else
{
DidYouMean(keyword); // Bunu mu aramıştınız metoduna çağrıda bulunuyoruz.
rptResults.DataSource = null;
rptResults.DataBind();//www.gorselprogramlama.com
}
}
public void DidYouMean(string keyword)
{
SqlConnection cnn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Data;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Select top 1 * From Konular Where DIFFERENCE(Baslik, @Kelime) >=3";
cmd.Parameters.AddWithValue("@Kelime", keyword);
cmd.Connection = cnn;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt != null && dt.Rows.Count > 0)
{
ltlResultText.Text = string.Format("Bunu mu aramıştınız: <u style=’color:red’>{0}</u>", dt.Rows[0]["Baslik"].ToString());
}
else
{
ltlResultText.Text = "Arama kriterlerinize uygun sonuç bulunamadı.";
}//www.gorselprogramlama.com
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Search(txtKeyword.Text.Trim());
}
}
[/code]

