Last post Feb 26, 2010 10:41 AM by Kevin Alkema
Feb 18, 2010 04:39 PM|boehmap|LINK
I'm working on a library that stores information on various cases. The case table has several columns that contain descriptive strings on what happened in the case. I would like to create a single filter that returns all cases where the search string is
found in any of the columns. I've looked at Dynamic Data Filtering, but as far as I can tell, the "Contains" filter only allows you to connect to each column individually. Has anyone tried this?
Dynamic Data Filter
Feb 19, 2010 09:04 AM|Kevin Alkema|LINK
I've truggled with a similar thing. What I finally did wasn't the cleanest but worked for me. I ended up with a texbox and button on the master page header area. during page load I did something like:
string searchFor = ((TextBox)this.Master.FindControl("textSearch")).Text;
GridDataSource.Where = "Code==\"" + searchFor + "\" || Name.Contains(\"" + searchFor + "\") || Description.Contains(\"" + searchFor + "\")";
foreach (ControlParameter WhereParm in GridDataSource.WhereParameters)
if (((DropDownList)this.FindControl(WhereParm.ControlID).Controls).SelectedIndex > 0)
GridDataSource.Where += " && " + WhereParm.Name + " == " + ((DropDownList)this.FindControl(WhereParm.ControlID).Controls).SelectedValue;
GridDataSource.AutoGenerateWhereClause = false;
if ((Session["SearchFor"] == null) || (Session["SearchFor"].ToString() != searchFor))
Session["SearchFor"] = searchFor;
GridView1.PageIndex = 0;
Feb 19, 2010 10:03 AM|boehmap|LINK
That's sort of what I was afraid of having to do, but if it works it works. I'll give it a shot and let you know how it turns out.
Feb 23, 2010 05:04 PM|boehmap|LINK
I haven't done much with "Where" statements. I'm guessing the Name, and Description are your columns. Is the "Code" also a column?
I tried just doing a simple copy and paste over to see what problems it would have. I have received a run time error when I reach the first "foreach" statement, saying "Unable to cast object of type 'System.Web.DynamicData.DynamicControlParameter' to type
'System.Web.UI.WebControls.ControlParameter'". I'm having trouble finding where this DynamicControlParameter is coming from in the debugger. Have you seen anything like this before? Any insight?
Feb 23, 2010 05:32 PM|Kevin Alkema|LINK
Yes "Code" is a column. And I have seen this before (as a matter of fact I had change it) it has to do with the filters. I'll double back and get you the answer.
btw you only have to do the foreach loop if there are filters and it only works as is if the filters are DropDownList's because "if (((DropDownList)this.FindControl(WhereParm.ControlID).Controls).SelectedIndex > 0".
Feb 26, 2010 05:32 AM|yacine|LINK
There is a cleaner approach you may want to try : try using a QueryExtender as follows :
<asp:QueryExtender ID="qe1" runat="server" TargetControlID="EntityDataSource1">
<asp:SearchExpression DataFields="field1,field2,etc" SearchType="Contains" />
ASP .NET Dynamic Data
Feb 26, 2010 10:41 AM|Kevin Alkema|LINK
Thanks for the suggestion. However, I'm using vs2008 and that isn't available. I will be using that for future projects once 2010 is released.