DataGrid Help

861
9
12-27-2010 02:26 PM
JoshShelton
New Contributor III
Hello,

I have implemented the find task as shown in the interactive SDK example: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Find
Everything works great but I would like to define what fields get returned in the datagrid when the find is executed. Can someone please help me with this? Is this done in the code behind? Or, do I need to do a Query on a featurelayer? I have been fighting with this for days now and I'm at a complete loss as to how to accomplish this. The field names I want to return are "pno_1" , "Owner_Nm" and URL.

Thank you for your help!

I'm using
Silverlight API 2.1 & VB.Net
0 Kudos
9 Replies
ScottFriedrich
New Contributor III
Josh,

In your case I would use a QueryTask, look at this sample:

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AttributeQuery

You can specify the Query Outfields that you want to be returned:

http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.Quer...

Good Luck,

Scott
0 Kudos
JoshShelton
New Contributor III
Thank you for your reply!

I've got the query task working but I am having a little trouble with the where clause. I want to query 2 fields with the value that is entered into my textbox. I have tried numerous different ways of doing this but I don't have a good grasp on the syntax... Basically the 2 fields contain numbers and I want to use the query to search both for the match. The fields are pno_1 and pno_2. Can someone help me with this as well?

Thank you all again for your help!!
0 Kudos
ScottFriedrich
New Contributor III
I am assuming the AND predicate is supported - you may have a datatype mismatch. Are they numeric or strings or boolean or ???

Strings require single quotes...

q.Where = "pno_1 = '" & FeatureQueryText.Text.Trim() & "' AND pno_2 = '" & FeatureQueryText.Text.Trim() & "'"

Numeric does not...
q.Where = "pno_1 = " & FeatureQueryText.Text.Trim() & " AND pno_2 = " & FeatureQueryText.Text.Trim()

Good Luck,

Scott
0 Kudos
JMcNeil
Occasional Contributor III
Josh you have a few different questions and different conflicting statements in each of your post so I'm not sure what you are really after at this point...

If you want to query different fields...specified in the second post.
If you implemented the find task...then it is in the code behind (#C).  You need to adjust this line:
 
 findParameters.SearchFields.AddRange(new string[] { "CITY_NAME", "NAME", "SYSTEM", "STATE_ABBR", "STATE_NAME" });


"CITY_NAME", "NAME", "SYSTEM", "STATE_ABBR", "STATE_NAME" - These are the fields that are searched.


If you are using the Query task then LochDhu is right on the right track use the and if both fields need to have the value or the OR predicate if either field should have the value. 

I think it would be something as easy as this:

 query.Where = string.Format("Field1 = 'TextBoxValue.Text' and Field2 'TextBoxValue1.Text'");


OR

 query.Where = string.Format("Field1 = 'TextBoxValue.Text' or Field2 = 'TextBoxValue1.Text'");




To try and answer you first question:  Which "fields get returned in the datagrid?"

For the Query task look in the code behind:
ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
            query.OutFields.Add("*");
            query.Text = QueryComboBox.SelectedItem.ToString();



This statement is returning your fields -   query.OutFields.Add("*");


I think to return the fields you specified
"pno_1" , "Owner_Nm" and URL.

query.OutFields.AddRange(new string[] { "pno_1", "Owner_Nm", "URL" });


For the FIND is taking place in the xaml it is bound to the data

 <slData:DataGrid.Columns>
                <slData:DataGridTextColumn Binding="{Binding Path=LayerId}" Header="Layer ID" />
                <slData:DataGridTextColumn Binding="{Binding Path=LayerName}" Header="Layer Name"/>
                <slData:DataGridTextColumn Binding="{Binding Path=FoundFieldName}" Header="Found Field Name" />
                <slData:DataGridTextColumn Binding="{Binding Path=Value}" Header="Found Field Value"/>
            </slData:DataGrid.Columns>


J
0 Kudos
JoshShelton
New Contributor III
Thank you all for your replies, and I apologize for the confusion. I am in no way a developer, or programmer... I have been given the task to create an interactive application and as thus I have to teach all of this to myself!!

My initial question was that my ultimate goal is to have a search tool that will search the fields I have specified and I want to control what displays in my results. This is the reason I asked if a find or a query (as shown on the interactive SDK examples) would be best to achieve the controlled output.

I can get the find tool to do all I need it to do but I cannot find a way to display only the fields I want to in the datagrid, I can only get the ones to display that are defined in the example:

<slData:DataGrid.Columns>
                <slData:DataGridTextColumn Binding="{Binding Path=LayerId}" Header="Layer ID" />
                <slData:DataGridTextColumn Binding="{Binding Path=LayerName}" Header="Layer Name"/>
                <slData:DataGridTextColumn Binding="{Binding Path=FoundFieldName}" Header="Found Field Name" />
                <slData:DataGridTextColumn Binding="{Binding Path=Value}" Header="Found Field Value"/>
            </slData:DataGrid.Columns>


Thanks to all of you and your generous replies I have tried to implement the query but the query does not return anything when using all of the different statements you provided.... Is it because I am doing this in VB and not C#? I can get it to return values if I do
query.Text = TextBox.Text

And I can control the fields that it returns (just like I want) but I want to search multiple fields not just the primary display field (if the query is the method I should be using....) The fields pno_1 and pno_2 (I forgot this field in my initial post) contains 12 digit numbers that I want to search. Owner_Nm is a field with names (First Last) and URL is a field that contains a URL that I want to display in the output not use in a find or query.

Again I apologize for my ignorance and any confusion I have caused. I am completely new to all of this and I am definately confused myself!
0 Kudos
AliMirzabeigi
New Contributor
Josh,

If the use-case you are trying to solve is searching features with multiple attributes with "AND" query then I would suggest you to use "Query" and "QueryTask" objects instead. All you need to do in this SDK sample is to set the appropriate "Where" clause; i.e. assuming you have two TextBox controls (TextBox1 and TextBox2 in the code snippet below) for the fields you are querying against the where clause should look like the following:
query.Where = string.Format("pno_1={0} AND pno_2={1}", TextBox1.Text, TextBox2.Text);

Regarding the issue you have/had in your DataGrid, the Binding statements in your XAML are still pointing to the attributes in the SDK sample and you need to use bindings to the attributes in your service instead (i.e. pno_1, pno_2, etc...)
0 Kudos
JoshShelton
New Contributor III
Thanks Ali,

How do I bind to my attributes in the find task?
0 Kudos
AliMirzabeigi
New Contributor
There is a "Feature" object in the "FindResults" object hence; you can bind to an attribute of yours like the following:
<slData:DataGridTextColumn Binding="{Binding Path=Feature.Attributes[pno_1]}" Header="pno_1" />
0 Kudos
JoshShelton
New Contributor III
Ali, thank you so much for your help!!!! This solved all of my problems!!! I have been trying to get this to work for a while now. I was missing the Feature in "{Binding Path=Feature.Attributes[pno_1]}" That is the reason I created this post, because I didn't know you could bind to an attribute of choice when using the find task.

Thank you to everyone for all of your help!!
0 Kudos