I tried this way, but then only "COMPANY_NM" as a datakey.
.DataKeys(k => k.Add(o => o.EXP_ID))
.DataKeys(k => k.Add(o => o.EMP_ID))
.DataKeys(k => k.Add(o => o.COMPANY_NM))
Below is for onw primary key.
14 Answers, 1 is accepted
Try this way:
Html.Telerik().Grid(Model.ProjectDetails) .Name("Grid") .DataKeys(dataKeys => { dataKeys.Add(m => m.ProjectID); dataKeys.Add(m => m.PictureID); } ) .DataBinding(...)...thx,
erick
Multiple datakeys are assigned like this:
.DataKeys(dataKeys => { dataKeys.Add(m => m.ProjectID); dataKeys.Add(m => m.PictureID).RouteKey("pictureId"); } )The only tricky thing is that you need to assign a unique RouteKey to the keys otherwise they will be send as "id".
Regards,
Atanas Korchev
the Telerik team
The only tricky thing is that you need to assign a unique RouteKey to the keys otherwise they will be send as "id". -> can u elaborate more on this??
the tricky part for me is when user editing the record in Master/Details grid,
ie: got 2 DataKeys(ProjectID, OwnerName) and several Columns(col1, col2, ...)
user only able to edit col1, col2, ... because the two DataKeys is for me to search in my records
also when adding a new one, User can input OwnerName, col1, col2, ... because the ProjectID is from the Master record..
any idea?
thx,
erick
If you have a single data key it is sent to the server as "id" unless you set its RouteKey.
However if you have more than one data key you must set the RouteKey of at least one of them. Here is how the action method would look like:
public ActionResult Save(int id, int pictureId)
{
}
Regards,
Atanas Korchev
the Telerik team
yes..it can be used like that (just found out now)
what if i want to pass the oldvalue for "id" and "pictureId" so i can retrieve it correctly before updating it?
thx,
erick
What do you mean by "old value"? The grid will submit the current value of the data key.
Regards,Atanas Korchev
the Telerik team
in Order i have : OrderID as PK,
in OrderLines i have: OrderID, ProductID as PK which become FK to Order, Qty, Price, etc
i displayed it using Ajax Master/Detail grid and give the User ability to edit the Lines whenever User retrieve the OrderID from Database
the initial Order:
OrderID: 1
- Line1: ProductID: 2, Qty: 10, Price: 20
- Line2: ProductID: 3, Qty: 100, Price: 200
User edit the first line become:
- Line1: ProductID: 4, Qty: 10, Price: 20
i must retrive the old Line1 record first from DB right (retrieve using OrderID, ProductID key) so i can edit its value to the new one?
thx,
erick
You should retrieve the parent OrderID value from the parent dataItem. Then you can use the OnSave event to send that value to the server:
function onSave(e) {
var parentGrid = $("#ParentGrid").data("tGrid");
var parentRow = $(this).closest("tr");
var parentDataItem = parentGrid.dataItem(parentRow);
e.values.OrderID = parentDataItem.OrderID; // values is sent to the server.
}
Regards,
the Telerik team
no idea how to do that...
gonna try Server binding then
thx for the clarification Atanas Korchev, been trying for 2 days
thx,
erick
Multiple datakeys are assigned like this:
//VIEW
.DataKeys(dataKeys => { dataKeys.Add(m => m.ID).RouteKey("id"); dataKeys.Add(m => m.TP).RouteKey("tp");
dataKeys.Add(m => m.NAME).RouteKey("name");
dataKeys.Add(m => m.LASTNAME).RouteKey("lastname"); } )
//CONTROLLER
[HttpPost]
public ActionResult Edit(int id, string tp, string name, string lastname, FormCollection formValues)
{
}
this way I have implemented up to 4 DataKeys and it has worked, hence the name of RouteKey ("id") should be receiving the same function in the controller.
I hope this solution to your liking.
Attentively,
Hernando Lamprea
DCA TECHNOLOGY LTDA
www.dcatech.com i understand it will referencing in the controller as u said, but i can't update it since i give the ability for User to update the Details line
i think i need to add PrimaryKeys that can't be updated so i can use your and Atanas method
thx,
erick
Did you create new PK? or you got any new solution ?