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

Multi-part keys FindItemByKeyValue

4 Answers 226 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 19 Apr 2011, 04:23 PM
Hi, I'm using your example from http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/clienteditbatchupdates/defaultcs.aspx.  Everything works great except the update and I've spent too long trying to get it to work.

I have a 3 part column key (DataKeyNames="Col1,Col2,Col3").  In the RadAjaxManager_AjaxRequest I'm passing back the values of the keys, but what is the proper syntax (or method) to retrieve the GridDataItem object. 

RadGrid1.MasterTableView.FindItemByKeyValue(keyname, keyvalue); ????

Thanks.

4 Answers, 1 is accepted

Sort by
0
Bill
Top achievements
Rank 1
answered on 20 Apr 2011, 01:59 PM
Can anyone help with this?
0
Vasil
Telerik team
answered on 22 Apr 2011, 12:36 PM
Hello Bill,

You could find the item by any of the three key values and it will be the same item.
GridDataItem updatedItem = RadGrid1.MasterTableView.FindItemByKeyValue("Col1", com1value);

Just have to make sure that you have not changed the value of the field by which you are looking for.
For example:
You have Col1, Col2, and Col3. You can change the text in the second column and then use Col1 or Col3 to access the original data item.

If you set DataKeyNames="ProductID,ProductName" in the code of the online demo, the same code-behind will still be valid and the update function will works.

All the best,
Vasil
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
Bill
Top achievements
Rank 1
answered on 03 May 2011, 06:51 PM
Thanks for the response, but i'm still somewhat confused.

What if i had the following data with the datakeynames="Col1,Col2"

Col1        Col2                    Col3
widget1    subwidget1         mycolumndata
widget1    subwidget1.1      **changeddata**
widget2    subwidget2         morecolumndata

So the user has modified the second row (Col1=widget1; Col2=subwidget1.1).  If I find item the griddataitem by using RadGrid1.MasterTableView.FindItemByKeyValue("Col1", widget1) it will return the first row - which is wrong.  This was the reason for my first question, how to i retrieve a griddataitem when the uniqueness is by more than just one column?

Thanks..Bill
0
Vasil
Telerik team
answered on 05 May 2011, 09:51 AM
Hi Bill,

You could use FindItemsByKeyValues function and pass dictionary with all data key values.

Hashtable dictionary = new Hashtable();
dictionary.Add("Col1", "widget1");
dictionary.Add("Col2", "subwidget1.1");
GridDataItem[] items = grid.MasterTableView.FindItemsByKeyValues(dictionary);

Greetings,
Vasil
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.

Tags
Grid
Asked by
Bill
Top achievements
Rank 1
Answers by
Bill
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or