Click here to Skip to main content
15,906,341 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I guys, Please can anyone help, i want to filter the content of a gridview on text change in a text box. The gridview have already been populated with data when the page loads.

Thanks
Posted
Comments
joshrduncan2012 7-Mar-13 10:43am    
This isn't a question. We need a lot more info as to what exactly you are doing.
ahmedfaruk88 7-Mar-13 10:45am    
Am trying to dynamically filter the content of a gridview on text change of textbox. The gridview contains more than 300 rows of data, and it takes the users time when traversing in it looking for a particular employee info with the specified name
[no name] 7-Mar-13 10:51am    
That still is not a question. Nor is it a description of the problem that you are having with any code. Please post the code that demonstrates your problem and clearly describe the problem that you are having. Are you getting any errors when you run your filtering code? What errors are they?
ahmedfaruk88 7-Mar-13 10:54am    
I am not getting any error, but clueless on how to go about it
[no name] 7-Mar-13 11:19am    
Clueless on how to go about what exactly? Creating a textbox text change event? Querying a database? Connecting to a database? Displaying data in a grid? Good luck finding a selectedindex change event for a textbox though.

1 solution

hi,

guess u can call OnTextChanged event in the codebehind and try to access the gridview from there.
below code might help:

C#
<asp:textbox id="TextBox1" runat="server" autopostback="true" ontextchanged="text" xmlns:asp="#unknown"></asp:textbox>


data access layer:
C#
public DataTable populategridview(int id)
  {
      SqlDataAdapter da = new SqlDataAdapter("select empname from development.dbo.employee where empid='" + id + "'", xconn);
      DataTable dt = new DataTable();
      da.Fill(dt);
      return dt;
  }


Codebehind:


C#
protected void text(object sender, EventArgs e)
{
    DAL obj2 = new DAL();
    int id = Convert.ToInt32(TextBox1.Text);
    DataTable dtnew = obj2.populategridview(id);
    grdview.DataSource = dtnew;
    grdview.DataBind();

}


try to do somethng like above..guess it should work..havent tested it though...:)

regards
anurag
 
Share this answer
 
Comments
ahmedfaruk88 7-Mar-13 11:17am    
Thanks i will implement it and get back to you

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