Hi,
I'm not sure why can but I can't seem to retrieve the value of my DateKey which I've specified on my Grid.
Here is the markup where is specify the DataKeyNames="Id":
Not sure if this really matters, but I don't specify the DataSourceID on the grid. Instead I set the datasource and bind the grid as follows:
I also set up the detail table like this:
Finally, I try to access the DataKey value ("Id") from the edit form on Update:
Could it be due to how I bind the grid instread of specifying the DataSourceID on the grid? I'm not actually sure what else to try? I really appreciate your help.
Thanks
I'm not sure why can but I can't seem to retrieve the value of my DateKey which I've specified on my Grid.
Here is the markup where is specify the DataKeyNames="Id":
<
telerik:RadGrid
ID
=
"grdCurrentNettpayDatails"
runat
=
"server"
CellSpacing
=
"0"
GridLines
=
"None"
AutoGenerateColumns
=
"False"
Skin
=
"Windows7"
AutoGenerateHierarchy
=
"True"
AllowPaging
=
"True"
OnUpdateCommand
=
"grdCurrentNettpayDetails_UpdateCommand"
PageSize
=
"15"
OnNeedDataSource
=
"grdDetails_NeedDataSource"
OnDetailTableDataBind
=
"grdDetails_DetailTableDataBind"
>
<
MasterTableView
HierarchyDefaultExpanded
=
"false"
DataKeyNames
=
"Id"
NoDetailRecordsText
=
"No payment records found."
>
Not sure if this really matters, but I don't specify the DataSourceID on the grid. Instead I set the datasource and bind the grid as follows:
grdDatails.DataSource = myDataSet;
grdDatails.DataBind();
I also set up the detail table like this:
protected
void
grdDetails_DetailTableDataBind(
object
sender, GridDetailTableDataBindEventArgs e)
{
var proxy =
new
MySDomainServicesoapClient();
var list=
new
List<Record>();
foreach
(GridDataItem dataItem
in
grdCurrentNettpay.MasterTableView.Items)
{
var checkBox = (dataItem.FindControl(
"CheckBox1"
)
as
CheckBox);
if
(checkBox !=
null
&& checkBox.Checked)
{
var recordId =
new
Guid(dataItem[
"Id"
].Text);
var record = proxy.GetRecrordsById(recordId).RootResults.SingleOrDefault();
list.Add(record);
}
}
proxy.Close();
var xmlDoc =
XmlHelper.GetStructuredXmlForRecords(
list);
var myDataSet= XmlHelper.GetHierarchicalDsFromXml(xmlDoc);
string
parentItemId = e.DetailTableView.ParentItem[
"Id"
].Text;
((RadGrid)sender).DataSource = myDataSet.Tables[1].Select(
"RecordId= "
+
"'"
+ parentItemId +
"'"
);
}
Finally, I try to access the DataKey value ("Id") from the edit form on Update:
protected
void
grdDetails_UpdateCommand(
object
sender, Telerik.Web.UI.GridCommandEventArgs e)
{
GridEditableItem gridEditFormItem = (GridEditableItem)e.Item;
var id=
new
Guid(gridEditFormItem.GetDataKeyValue(
"Id"
).ToString());
// Give me null!
}
Could it be due to how I bind the grid instread of specifying the DataSourceID on the grid? I'm not actually sure what else to try? I really appreciate your help.
Thanks
7 Answers, 1 is accepted
0

Jayesh Goyani
Top achievements
Rank 2
answered on 14 Nov 2011, 11:11 AM
Hello,
From your code i understand that you want to access parent grid's datakey on child row update.
for this try with below code.
Thanks,
Jayesh Goyani
From your code i understand that you want to access parent grid's datakey on child row update.
for this try with below code.
string
strId = (e.Item
as
GridEditableItem).OwnerTableView.ParentItem.GetDataKeyValue(
"ID"
).ToString();
Thanks,
Jayesh Goyani
0

Johan
Top achievements
Rank 1
answered on 14 Nov 2011, 11:42 AM
Hi Jayesh,
Thanks for responding to my question.
Thats right, I'm trying to read the parent grid's datakey on child row update.
I have just tried your suggestion but still get null:
Anything else I can try?
Thanks
Thanks for responding to my question.
Thats right, I'm trying to read the parent grid's datakey on child row update.
I have just tried your suggestion but still get null:
'(e.Item as GridEditableItem).OwnerTableView.ParentItem.GetDataKeyValue("Id")' is null
Anything else I can try?
Thanks
0
Hi Ryno,
I suggest that you examine the help article below and let me know if it helps to resolve the described problem:
http://www.telerik.com/help/aspnet-ajax/grid-extract-primary-key-for-parent-item-in-hierarchy-on-update-insert.html
Also verify that you have set DataKeyNames property.
Greetings,
Pavlina
the Telerik team
I suggest that you examine the help article below and let me know if it helps to resolve the described problem:
http://www.telerik.com/help/aspnet-ajax/grid-extract-primary-key-for-parent-item-in-hierarchy-on-update-insert.html
Also verify that you have set DataKeyNames property.
Greetings,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0

Jayesh Goyani
Top achievements
Rank 2
answered on 14 Nov 2011, 12:15 PM
Hello,
Can you please provide your grid's code or structure.
So i can identify at which (child)child level you want to get parent's datakey;
Thanks,
Jayesh Goyani
Can you please provide your grid's code or structure.
So i can identify at which (child)child level you want to get parent's datakey;
Thanks,
Jayesh Goyani
0

Jayesh Goyani
Top achievements
Rank 2
answered on 14 Nov 2011, 12:28 PM
Hello,
Try below code if you have second level child grid in edit mode.
Please add "
Let me know if any concern.
Thanks,
Jayesh Goyani
Try below code if you have second level child grid in edit mode.
string
strid = (e.Item
as
GridEditableItem).OwnerTableView.ParentItem.OwnerTableView.ParentItem.GetDataKeyValue(
"ID"
).ToString();
Please add "
OwnerTableView.ParentItem
" for every child grid to reach the parent item.Let me know if any concern.
Thanks,
Jayesh Goyani
0

Johan
Top achievements
Rank 1
answered on 14 Nov 2011, 01:42 PM
Hi,
Here is the complete markup of my grid:
Here is the complete markup of my grid:
<
telerik:RadGrid
ID
=
"grdDatails"
runat
=
"server"
CellSpacing
=
"0"
GridLines
=
"None"
AutoGenerateColumns
=
"False"
Skin
=
"Windows7"
AutoGenerateHierarchy
=
"True"
AllowPaging
=
"True"
OnUpdateCommand
=
"grdCurrentNettpayDetails_UpdateCommand"
PageSize
=
"15"
OnNeedDataSource
=
"grdCurrentNettpayDetails_NeedDataSource"
OnDetailTableDataBind
=
"grdCurrentNettpayDetails_DetailTableDataBind"
>
<
MasterTableView
HierarchyDefaultExpanded
=
"false"
DataKeyNames
=
"Id"
NoDetailRecordsText
=
"No payment records found."
>
<
DetailTables
>
<
telerik:GridTableView
runat
=
"server"
DataKeyNames
=
"PaymentId"
AutoGenerateColumns
=
"false"
>
<
ParentTableRelation
>
<
telerik:GridRelationFields
DetailKeyField
=
"PaymentInstructionId"
MasterKeyField
=
"Id"
/>
</
ParentTableRelation
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"AccountNumber"
DataType
=
"System.String"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"Account Number"
UniqueName
=
"AccountNumber"
ReadOnly
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"BranchCode"
DataType
=
"System.String"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"Branch Code"
UniqueName
=
"BranchCode"
ReadOnly
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"AccountType"
DataType
=
"System.String"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"Account Type"
UniqueName
=
"AccountType"
Visible
=
"true"
ReadOnly
=
"true"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
DataField
=
"Value"
DataType
=
"System.Decimal"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"Nett Value"
UniqueName
=
"Value"
ReadOnly
=
"false"
>
<
ItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"lblAmount"
Text='<%# Eval("value", "{0:C}") %>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"PayDate"
DataType
=
"System.String"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"Payroll Date"
UniqueName
=
"PayDate"
ReadOnly
=
"true"
>
</
telerik:GridBoundColumn
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
ItemStyle-HorizontalAlign
=
"Center"
EditImageUrl
=
"~/Content/Images/grid-edit-icon.png"
HeaderText
=
"Edit"
UniqueName
=
"EditCommandColumn"
>
</
telerik:GridEditCommandColumn
>
</
Columns
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
/>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
/>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
>
<
HeaderStyle
Width
=
"20px"
/>
</
ExpandCollapseColumn
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
>
</
EditColumn
>
</
EditFormSettings
>
</
telerik:GridTableView
>
</
DetailTables
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
Visible
=
"True"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Id"
DataType
=
"System.Guid"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"Id"
UniqueName
=
"Id"
Visible
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"CheckBoxTemplateColumn"
AllowFiltering
=
"false"
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"CheckBox1"
runat
=
"server"
OnCheckedChanged
=
"ToggleRowSelection"
AutoPostBack
=
"True"
/>
</
ItemTemplate
>
<
HeaderTemplate
>
<
asp:CheckBox
ID
=
"headerChkbox"
runat
=
"server"
OnCheckedChanged
=
"ToggleSelectedState"
AutoPostBack
=
"True"
/>
</
HeaderTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"DataTypeId"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"DataTypeId"
UniqueName
=
"DataTypeId"
Visible
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"EmployeeCode"
DataType
=
"System.String"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"Employee Code"
UniqueName
=
"EmployeeCode"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Surname"
DataType
=
"System.String"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"Surname"
UniqueName
=
"Surname"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"FirstNames"
DataType
=
"System.String"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"First Names"
UniqueName
=
"FirstNames"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Initials"
DataType
=
"System.String"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"Initials"
UniqueName
=
"Initials"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Sum"
DataType
=
"System.Decimal"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"Sum"
UniqueName
=
"Sum"
ReadOnly
=
"true"
>
</
telerik:GridBoundColumn
>
<%--<
telerik:GridBoundColumn
DataField
=
"value"
DataType
=
"System.Decimal"
FilterControlAltText
=
"Filter column column"
HeaderText
=
"Value"
UniqueName
=
"Value"
>
</
telerik:GridBoundColumn
>--%>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
>
</
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
ClientSettings
>
<
Scrolling
ScrollHeight
=
"400px"
></
Scrolling
>
<
ClientEvents
OnRowDblClick
=
"rowDblClick"
/>
</
ClientSettings
>
<
FilterMenu
EnableImageSprites
=
"False"
>
</
FilterMenu
>
<
HeaderContextMenu
CssClass
=
"GridContextMenu GridContextMenu_Default"
>
</
HeaderContextMenu
>
</
telerik:RadGrid
>
0

Jayesh Goyani
Top achievements
Rank 2
answered on 14 Nov 2011, 01:56 PM
Hello,
for first child grid
for second child grid
for more information, please also check below code snippet.
Let me know if any concern.
Thanks,
Jayesh Goyani
for first child grid
string
strid = (e.Item
as
GridEditableItem).OwnerTableView.ParentItem.GetDataKeyValue(
"Id"
).ToString();
for second child grid
string
strid = (e.Item
as
GridEditableItem).OwnerTableView.ParentItem.OwnerTableView.ParentItem.GetDataKeyValue(
"Id"
).ToString();
for more information, please also check below code snippet.
protected
void
RadGrid1_UpdateCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.Item.OwnerTableView.Name ==
"Child1"
)
{
string
strid = (e.Item
as
GridEditableItem).OwnerTableView.ParentItem.GetDataKeyValue(
"Id"
).ToString();
}
else
if
(e.Item.OwnerTableView.Name ==
"Child2"
)
{
string
strid = (e.Item
as
GridEditableItem).OwnerTableView.ParentItem.OwnerTableView.ParentItem.GetDataKeyValue(
"Id"
).ToString();
}
}
<
MasterTableView
DataKeyNames
=
"Id"
Name
=
"Parent"
>
<
Columns
>
............
............
</
Columns
>
<
DetailTables
>
<
telerik:GridTableView
Name
=
"Child1"
>
<
Columns
>
............
............
</
Columns
>
<
DetailTables
>
<
telerik:GridTableView
Name
=
"Child2"
>
<
Columns
>
............
............
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
</
telerik:GridTableView
>
</
DetailTables
>
</
MasterTableView
>
Let me know if any concern.
Thanks,
Jayesh Goyani