protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection("----"))
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * FROM TEST WHERE ID='"+TextBox1.Text+"'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable DT = new DataTable();
da.Fill(DT);
con.Close();
if (DT.Rows.Count > 0)
{
Response.Write("ALREADY HAVE");
}
else
{
}
}
}
[Update]
other wise u can use autocomplete textbox ..
http://www.aspdotnet-suresh.com/2012/08/using-jquery-autocomplete-with-aspnet.html[
^]
Auto complete Textbox in asp.net using ajax and c#[
^]
[Update]
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
ontextchanged="TextBox1_TextChanged"></asp:TextBox>
</div>
</form>
</body>
----------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection("----"))
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * FROM TEST WHERE ID='" + TextBox1.Text + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable DT = new DataTable();
da.Fill(DT);
con.Close();
if (DT.Rows.Count > 0)
{
Response.Write("ALREADY HAVE");
}
else
{
}
}
}
}