c# - How to filter gridview from textbox? -


i need filter gridview retreives filtered data table. therefore bound gridview dataset. can't seem find solution filter further.

protected void page_load(object sender, eventargs e) { if (!ispostback)     {         dataset ds = new dataset();         sqlconnection mycon = new sqlconnection(connectionstring);         sqldataadapter adapter = new sqldataadapter(cmd, mycon);         adapter.fill(ds);         gridview1.datasource = ds;         gridview1.databind();     } } protected void button1_click(object sender, eventargs e) { //need insert code here filtering gridview1 based on textbox1.text         } 

thanks help.

try this:

protected void button1_click(object sender, eventargs e) {      dataset ds = new dataset();     sqlconnection mycon = new sqlconnection(connectionstring);     sqldataadapter adapter = new sqldataadapter(cmd, mycon);     adapter.fill(ds);     dataview view = new dataview();     view.table = ds.tables[0];     view.rowfilter = "columnname = " + textbox1.text.trim();     gridview1.datasource = view;     gridview1.databind(); } 
  • you have refactor code.

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -