try this this my sample code... you have to change it
void bindsearch()
{
if (txtcname.Text == "" && txtdname.Text == "" && ddlicense.SelectedItem.Text == "All" && ddStatus.SelectedItem.Text == "All")
{
bind();
return;
}
string str = "";
if (txtcname.Text.Trim() != "")
{
str = "and ClientMst.ClientName like '%" + txtcname.Text.Trim() + "%'";
}
if (txtdname.Text.Trim() != "")
{
str = "and ClientMst.DisplayName like '%" + txtdname.Text.Trim() + "%'";
}
if (txtcname.Text.Trim() != "" && txtdname.Text.Trim() != "")
{
str = "and ClientMst.ClientName = '" + txtcname.Text.Trim() + "'";
}
if (ddStatus.SelectedItem.Text.Trim() != "All")
{
str = str + "and Active ='" + ddStatus.SelectedValue.Trim() + "'";
}
if (ddlicense.SelectedItem.Text.Trim() != "All")
{
str = str + "and License ='" + ddlicense.SelectedValue.Trim() + "'";
}
princ.Columns[1].Visible = true;
string query = " select ClientID,ClientName,DisplayName,ContPerson,contmob,case when License=1 then 'Full' else (Replace(convert(Varchar(20),Period,113),' ','/')) end as License, " +
" Period,case when Active=0 then 'Yes' else 'No' end as Active " +
" from ClientMst where ClientID<>'' " + str + " ";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count != 0)
{
princ.DataSource = dt;
princ.DataBind();
}
else
{
ddStatus.ClearSelection();
ddlicense.ClearSelection();
txtcname.Text = "";
txtdname.Text = "";
bind();
MessageInfo.MessageIcon = MessageIcons.ErrorIcon;
TMessageBox1.Show(this.Title, "NO Record", (TMessageBox.MessageIcons)MessageInfo.MessageIcon, true);
return;
}
princ.Columns[1].Visible = false;
}