How to filter data from gridview on demand by using datasour
I have binded the gridview by using datasource then how to filter from it by perticular selecting couloumn value? and how to paging by using dropdwonlist?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pradeep ShetRank #595 · 4K reputationPosted Apr 15, 2015, 9:50 PM EDT
1) Once data is bound store that dataset in a ViewState["data"]
2) Based on total row count / 10 (page size), fill the dropdown from 1 to result received by division
3) On PageChangeIndexChnaged, write a logic for getting partiuclar set of records from ViewState and bind the gridview again
4)For search bind all columnNames in the dropdownlist and one textbox for search text
ddlSearchColumns.DataSource = ds.Tables[0].Columns
ddlSearchColumns.DataBind()
5)On search click,
DataSet ds = (DataSet)ViewState["data"];
DataRow[] drs = ds.Tables[0].Select(ddlSearchColumns.SelectedValue + "='" + txtSearch.Text + "'");
You will get the DataRow array of result, convert it back to datatable
DataTable dt1 = dr.CopyToDataTable();
Then bind it back to gridview
Plz mark it as answered if this solves your problem
dawood abbas43 reputationPosted Apr 15, 2015, 10:10 PM EDT
Actually I stored in viewstate then can filter on it but cant apply paging. so I bound data by using 'SqlDatasource' in aspx page not by dataset so I thought its easy to paging from this but still in searching it.
Pradeep ShetRank #595 · 4K reputationPosted Apr 19, 2015, 12:08 PM EDT
http://www.codeproject.com/Articles/67520/GridView-Paging-and-Sorting
Santhakumar MunuswamyRank #128 · 17.3K reputationPosted Apr 19, 2015, 12:16 PM EDT
Refer this below link
http://san2debug.net/post/How-to-Gridview-Header-Filtering-in-Aspnet.aspx