Birçok TextBox koymana gerek yok. 1tane TextBox ,1 de DropDownList koy ve arama yaptıracağın alanı Droptan seç, arayacağın kelimeyi de Texte yaz.
protected void LinkButton2_Click(object sender, EventArgs e)
{
string sql;
if (DropDownList1.SelectedItem.Text == "Adı")
{
sql = "select * from tbl_emlakteklif where ad like '%" + TextBox1.Text + "%' " + "order by id DESC";
}
else if (DropDownList1.SelectedItem.Text == "Soyadı")
{
sql = "select * from tbl_emlakteklif where soyad like '%" + TextBox1.Text + "%' " + "order by id DESC";
}
else if (DropDownList1.SelectedItem.Text == "Telefon")
{
sql = "select * from tbl_emlakteklif where tel like '%" + TextBox1.Text + "%' " + "order by id DESC";
}
else if (DropDownList1.SelectedItem.Text == "Açıklama")
{
sql = "select * from tbl_emlakteklif where aciklama like '%" + TextBox1.Text + "%' " + "order by id DESC";
}
else
{
sql = ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,";
}
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
SqlCommand komut = new SqlCommand();
komut.CommandText = sql;
komut.CommandType = CommandType.Text;
komut.Connection = conn;
DataTable MyTable = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = komut;
adapter.Fill(MyTable);
if (MyTable != null && MyTable.Rows.Count > 0)
{
GridView1.DataSource = MyTable;
GridView1.DataBind();
}
else
{
Alert.Show(" Kayıt bulunamadı.");
}
adapter.Dispose();
komut.Dispose();
conn.Dispose();
}