This is a migrated thread and some comments may be shown as answers.

Use of FindItemsByKeyValues troubles

8 Answers 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jesús
Top achievements
Rank 1
Jesús asked on 29 Apr 2011, 11:39 AM
Hi.

I'm using a RadGrid object and I want to find an item by its keys values.

The dictionary is a Hashtable that is filled with a foreach iteration.

Hashtable d = new Hasthable();
for (int i = 0; i < partK.Length; i++)
{
    d.Add(partK[i], partV[i]);
}
GridDataItem[] gdis = listGrid.MasterTableView.FindItemsByKeyValues(d);

I'm using the following example. Dictionary d is filled with the following values:

-       d   Count = 2   System.Collections.Hashtable
+       ["MVFCodCIA"]   "035"   
+       ["MVFRefXRisk"]   "70000598"   

At the listGrid, if I make the following question at the inspection window I have this:

listGrid.Items[7].KeyValues   "{MVFCodCIA:\"035\",MVFRefXRisk:\"70000598\"}"   string

So the item exists.

When I debug the code, gdis.Length is 0, so the FindItemsByKeyValues doesn't find me the item I'm searching.

Am I doing something wrong?

Thanks.

8 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 04 May 2011, 11:03 AM
Hi,

The code and the approach you are using is indeed proper. However, can you confirm you have added the MVFCodCIA and MVFRefXRisk fields to the DataKeyNames collection of the MasterTableView?

Kind regards,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Sean
Top achievements
Rank 1
answered on 19 May 2011, 10:52 PM
Has there been a resolution to this issue?

I'm running into the same issue where the FindItemsByKeyValues returns a 0 length GridDataItem array.

I have verified that the datakeys are declared on the master table.

Thanks for your assitance in advance.
Sean
0
Iana Tsolova
Telerik team
answered on 25 May 2011, 11:13 AM
Hi Sean,

Please find the attached sample illustrating how the method in question works. Can you try it on your end and let me know how it goes and what differs in your case.

Best wishes,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Sean
Top achievements
Rank 1
answered on 25 May 2011, 02:52 PM
Hello Iana,

Thank you for the response and the example app.  I've tried to implement this into our project without success.  The items object comes up with a 0 length.

Here is a brief background on our scenario.  RadGrid1 can contain row data that belongs to a user.  We have a composite key (or multiple DataKeys) on this RadGrid1.  ASSIGNED_TECH, HD_TICKET_ID  So I've modified the hashtable to reflect that:

Dim myValues As New Hashtable
myValues("ASSIGNED_TECH") = Session("emailAddress")
myValues("HD_TICKET_ID") = Session("ticket")

When I apply the FindItemsByKeyValues it looks like this:
Dim myAssignments As GridItem() = RadGridAssignments.MasterTableView.FindItemsByKeyValues(myValues)

myAssignments returns a 0 length.  We'd like to access the GridItemData eventually too.  So i'm not sure if the GridItem object can be replaced with the GridDataItem object or not. 

We are then using this in another grids (RadGrid2) ItemDataBound event to prepopulate certain fields in a Insert Form Template. 

Hope this helps narrow something down.

Thanks!
Sean
0
Iana Tsolova
Telerik team
answered on 25 May 2011, 03:29 PM
Hi Sean,

Indeed, you can cast each of the grid items to GridDataItem as all grid items (data item, pager item, filtering item, etc.) inherit from the GridItem class.

However can you send me a sample of your grid in a formal support ticket? Thus I will run it and debug it locally and be able to find what went wrong there.

All the best,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Jesús
Top achievements
Rank 1
answered on 26 May 2011, 09:59 AM
I discovered what's my trouble. I'm looking for a data item that is not in the MasterTableView because it's in another page.

In our application we have a form to insert data, and the we refresh a list with all the data table. We want to select the recently added register, but it's possible it will be at another page (and it's not mandatory it will be the last register).

Is there any way to look for a register and mark it as the selected item?
0
Accepted
Iana Tsolova
Telerik team
answered on 26 May 2011, 12:26 PM
Hello,

There are two approaches you can use to achieve your goal:
    - You should either loop through all grid pages and their items to find the specific item. 
    - Or you can find which is the index of the item in the datasource bound to the grid directly. Then calculate on which page and what item index the record would have in the grid. Navigate to that page and add the index to the SelectedIndexes collection.

Check it out and let me know if you have further questions.

Greetings,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Jesús
Top achievements
Rank 1
answered on 26 May 2011, 12:29 PM
I discovered the second chance by my own :)

Thanks.
Tags
Grid
Asked by
Jesús
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Sean
Top achievements
Rank 1
Jesús
Top achievements
Rank 1
Share this question
or