how to code for dynamic search

Posted by Parthibansk under ASP.NET on 5/23/2013 | Points: 10 | Views : 983 | Status : [Member] | Replies : 2
have a scenario to retrive data from dynamic search and bind in grid..

select one value form dropdownlist and enter keyword in textbox and then bind..



EX: SELCT ID (or) NAME (or) DEPT FROM DDL AND ENTER DESIRED KEYWORD IN TEXTBOX AND SEARCH...

my code not working...

public void BindData()
{
SqlCommand cmd;
cmd = new SqlCommand("sp_GetEmployeeDetails", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@roll", SqlDbType.VarChar)).Value = DropDownList1.SelectedValue;
cmd.Parameters.Add(new SqlParameter("@Name", SqlDbType.VarChar)).Value = TextBox1.Text;

con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataTable dt = new DataTable("Table");
da.Fill(dt);
con.Close();
GridView1.DataSource = dt;
GridView1.DataBind();

}

STORED PROC:

CREATE PROCEDURE sp_GetEmployeeDetails @Dept Int,
@Name nvarchar(30)

AS
SELECT *

Select * from Emptab where EmpName=@Name and DeptID=@Dept
GO




Responses

Posted by: Bageshkumarbagi on: 5/23/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

You can write search code in textbox event call "TextChanged "or "TextLeave".


Thanks,
Bagesh Kumar Singh

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 5/28/2013 [Member] Starter | Points: 25

Up
0
Down
Use Like Clause to perform the dynamic search

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response