Hi Kishore,
I think we can do by using WHERE condition in the SQL query itself... Look into the following code...
[code]
protected void Page_Load(object sender, EventArgs e)
{
string LastName = ""; //Pass on your string value
if (!IsPostBack)
{
BindGrid(LastName);
}
}
private DataTable GetRecords(string LastName)
{
// Fill in your database details; else use web.config method
string strConnection = "SERVER=XXXXX;Database=XXXXX;User Id=XXXX;Password=XXXXX";
SqlConnection conn = new SqlConnection(strConnection);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText =
"Select * from DotNet.Employees where last_name = '" + LastName + "';";
SqlDataAdapter dAdapter = new SqlDataAdapter();
dAdapter.SelectCommand = cmd;
DataSet objDs = new DataSet();
dAdapter.Fill(objDs);
return objDs.Tables[0];
}
private void BindGrid(string bndLastName)
{
DataTable dt = GetRecords(bndLastName);
if (dt.Rows.Count > 0)
{
grdSearch.DataSource = dt;
grdSearch.DataBind();
}
}[/code]
Note: Alternate method is to use GridView along with Search Button
Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif
Kishore463, if this helps please login to Mark As Answer. | Alert Moderator