Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Actually i am having a form with search text-box1. in that if enter any name or registration_id it should display gridview with related details...i am getting the result but not in a correct way...i taken text-box1_text-changed event after going from text-box1.but while entering only i want to see the details
//this was my sql-query
SQL
select * from student_details where (child_name like @Student_ID or student_id like @Child_Name) and School_Name=@School_Name
//this was my .cs code
protected void txtSearch_TextChanged(object sender, EventArgs e)
       {
           gridviewCandidateDetails.Visible = true;
           SqlCommand cmdSearch = DBManager.DataAccess.command();
           cmdSearch.Parameters.Add(new SqlParameter("@option", SqlDbType.VarChar, 50));
           cmdSearch.Parameters["@option"].Value = "SearchByNameOrRegistrationID";

           cmdSearch.Parameters.Add(new SqlParameter("@School_Name", SqlDbType.NVarChar, 200));
           cmdSearch.Parameters["@School_Name"].Value = Session["SchoolName"].ToString();

           cmdSearch.Parameters.Add(new SqlParameter("@Student_ID", SqlDbType.VarChar, 50));
           cmdSearch.Parameters["@Student_ID"].Value = txtSearch.Text;

           cmdSearch.Parameters.Add(new SqlParameter("@Child_Name", SqlDbType.VarChar, 50));
           cmdSearch.Parameters["@Child_Name"].Value = txtSearch.Text;

           string sqlquery = "SchoolProc";
           DataSet dsPickSearchDetails = DBManager.DataAccess.getdata(sqlquery);
           if (dsPickSearchDetails.Tables[0].Rows.Count > 0)
           {
               gridviewCandidateDetails.DataSource = dsPickSearchDetails.Tables[0];
               gridviewCandidateDetails.DataBind();
               txtSearch.Focus();
           }
           else
           {
               string strScript = "<script>";
               strScript += "alert('Sorry No records Available');";
               strScript += "</script>";
               Page.RegisterClientScriptBlock("strScript", strScript);
               gridviewCandidateDetails.Visible = false;
               txtSearch.Focus();
           }
       }<pre>
Posted
Updated 28-Feb-13 19:11pm
v2

1 solution

Server side asp.net textbox text changed is fired when you going to lose focus from that textbox. Not every character change and it will fire. In that case my suggestion is you go for ajax approach. You handle client side onkeydown/onkeypress event from javascript and you send request to server for jason data with asynchronous get request(ajax) and receive data from success callback and you update your ui with that data. It need some extra effort but if you go for that it will provide you better user experience. You can go jquery site for ajax help also you can check autocomplete tool for jquery ui.
 
Share this answer
 
Comments
ntitish 1-Mar-13 2:06am    
sir i am not having any knowledge of Ajax or java script till now i not used both in my website....but i want this search functionality in my web form...sir if u dont mind if u had knowledge means can u send me code sir...
S. M. Ahasan Habib 1-Mar-13 3:22am    
You just start study on that then in web you can find so many code sample. You can start from the following link.
http://www.codeproject.com/Articles/17203/Using-jQuery-for-AJAX-in-ASP-NET

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900