Select to view content in your preferred language

Query Question

2049
3
03-02-2011 08:24 AM
JayKappy
Frequent Contributor
I have seen a couple apps that have radio buttons/check boxes in a TOC...where the user selects a few and it queries some data source and returns the recrods that pertain to those selected.

http://gis.anokacountymn.gov/go-anoka/

I assume that:
There is a field for each in a feature class (say a parcels data source), boolean?
then the user selects the radio buttons/check boxes
A query is then built search for recods with all the selected radio buttons/check boxes that were selected.

Is this how soemthing like that is done....I am somewhat confident I can get the final query built...WHERE A AND B AND C AND D

But am having a hard time with the querying what radio buttons are clicked to build the query
If RadioButtonA Then
Else if RadioButtonB Then
Etc etc

Any thoughts would be greatly apprecited?
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
So the question is, how to identify which radio button is clicked?

You can look at this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SwitchMap

The radio buttons in the sample above is used to switch base layer url. Notice that all radio button use the same RadioButton_Click event. In XAML, notice also that RadioButton.Tag is used to hold the url. Another way is to check by instance.
RadioButton rb = sender as RadioButton
if(rb == this.StreetsRadioButton){}
else if(rb == this.TopoRadioButton){}
else{}
0 Kudos
JayKappy
Frequent Contributor
I might have misspoke...in the example I gave they were actually Check boxes...the users selects a few check boxes in the "What activity do you want to do" and it seems to be quering a feature class....I assume that the feature class has a field for each activity....the query is built to find each records that has the checked values...
I am just unclear how to create that query...lots of AND statements?
But imagin there has to be some sort of loop, else statement to first determine which are checked.

Thanks
0 Kudos
JenniferNery
Esri Regular Contributor
You can use StringBuilder to build the Where clause and Dictionary to hold the field name and value pair.

You can change the equality sign as you wish too.
StringBuilder sb = new StringBuilder();
int count = 0;
foreach (var item in items)
{    
 if(count == 0)
  sb.Append(string.Format("{0} > {1}", item.Key, item.Value));
 else
  sb.Append(string.Format(" and {0} > {1}", item.Key, item.Value));
 count++;
}
query.Where = sb.ToString();


The following code assumes that each CheckBox Content is the field name, each field accepts an integer value.
private Dictionary<string, int> items = new Dictionary<string, int>();
private void CheckBox_Click(object sender, RoutedEventArgs e)
{
 CheckBox cb = sender as CheckBox;
 string key = (string) cb.Content;
 if (items.ContainsKey(key))
  items.Remove(key);
 else
  items.Add(key, Convert.ToInt32(NumValue.Text.Trim()));
}
0 Kudos