I built a Shared Categories Filtering app on my current .text project which I'll discuss more later. For the moment I wanted to share a tip on rebinding the resulting search results to a datagrid without re-executing the search. The search is executed by keyword against a master list of shared categories. The results are bound to a datagrid. The user selects the shared category he or she wants added to their available list by clicking the button circled in the screenshot here, and that item is removed from the search results list using the technique shown below.
Howto: When the search is performed and the results bound to the datagrid, the DataTable is stored in ViewState. When item is selected, the DataTable is retrieved from ViewState, the item matching the id selected is removed, and the datagrid is rebound. Sweet and easy.
DataTable dt = (DataTable)ViewState["SearchDataTable"];
for(int i = 0; i< dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
if ((int)dr["termID"] == _termID)
dt.Rows.Remove(dr);
}
dt.AcceptChanges();
dgTerms.DataSource = dt.DefaultView;
dgTerms.DataBind();