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

ParentItem Columns from RadGrid1_UpdateCommand

1 Answer 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 1
Darren asked on 22 May 2008, 12:35 AM

  I'm trying to access the parent item column values from a detail grid in the RadGrid1_UpdateCommand event.  I've tried the various methods below which do not work.  How can this be done?

Thanks

.cs

protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)

{

//Get the GridEditableItem of the RadGrid

GridEditableItem editedItem = e.Item as GridEditableItem;

string xref_map_id;

string xref_map_key;

string xref_map_description;

string in_dataType;

string out_dataType;

 

if (e.Item.OwnerTableView.Name == "Detail")

{

//Need to get the parent row values here

//GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem; //doesn't work

//GridDataItem dataItem = e.Item.OwnerTableView.ParentItem; //doesn't work

//cast the item to GridEditFormItem

GridEditFormItem formItem = e.Item as GridEditFormItem;

//reference its parent data item

GridDataItem dataItem = formItem.ParentItem as GridDataItem;

xref_map_key = dataItem[

"XREF_MAP_KEY"].Text;

xref_map_id = dataItem[

"XREF_MAP_ID"].Text;

date_updated = dataItem[

"DATE_UPDATED"].Text;

xref_map_description = dataItem[

"XREF_MAP_DESCRIPTION"].Text;

in_dataType = dataItem[

"IN_DATA_TYPE"].Text;

out_dataType = dataItem[

"OUT_DATA_TYPE"].Text;

etc.


aspx:

<%

@ Page Language="C#" MasterPageFile="~/Navigation1.Master" AutoEventWireup="true" CodeBehind="AdminMapData.aspx.cs" Inherits="EAI_Dashboard.AdminMapData" Title="Map Data Administration" %>

<%

@ Register Assembly="RadAjax.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>

<%

@ Register Assembly="RadCalendar.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>

<%

@ Register Assembly="RadInput.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>

<%

@ Register Assembly="RadComboBox.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>

<%

@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>

<

asp:Content ID="Content1" ContentPlaceHolderID="_titleContent2" runat="server">

Map Data Administration

</

asp:Content>

<

asp:Content ID="Content2" ContentPlaceHolderID="_mainContent2" runat="server">

<rad:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource" OnUpdateCommand="RadGrid1_UpdateCommand" OnInsertCommand="RadGrid1_InsertCommand" OnDeleteCommand="RadGrid1_DeleteCommand" OnDetailTableDataBind="RadGrid1_DetailTableDataBind" EnableAJAX="True" AutoGenerateColumns="False" PageSize="25" Width="100%">

<MasterTableView Name="Master" DataKeyNames="XREF_MAP_ID" PageSize="15" AllowFilteringByColumn="True" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False">

<DetailTables>

<rad:GridTableView CommandItemDisplay="Top" Name="Detail" Width="100%" AllowSorting="False"

runat="server" PageSize="10" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Size="X-Small" Font-Strikeout="False" Font-Underline="False">

<Columns>

<rad:GridBoundColumn DataField="ATTRIBUTE_DESCRIPTION" HeaderText="Attribute Description"

SortExpression="ATTRIBUTE_DESCRIPTION" UniqueName="ATTRIBUTE_DESCRIPTION" >

</rad:GridBoundColumn>

<rad:GridBoundColumn DataField="PARM_NAME" HeaderText="Parm Name"

SortExpression="PARM_NAME" UniqueName="PARM_NAME" ReadOnly="True" Visible="False">

</rad:GridBoundColumn>

<rad:GridEditCommandColumn>

</rad:GridEditCommandColumn>

<rad:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column">

</rad:GridButtonColumn>

</Columns>

<ExpandCollapseColumn Resizable="False" Visible="False">

<HeaderStyle Width="20px" />

</ExpandCollapseColumn>

<RowIndicatorColumn Visible="False">

<HeaderStyle Width="20px" />

</RowIndicatorColumn>

<HeaderStyle BackColor="Olive" Font-Bold="False" Font-Italic="False" Font-Overline="False"

Font-Size="X-Small" Font-Strikeout="False" Font-Underline="False" Wrap="True" ForeColor="White" HorizontalAlign="Center" />

</rad:GridTableView>

</DetailTables>

<ExpandCollapseColumn Resizable="False">

<HeaderStyle Width="20px" />

</ExpandCollapseColumn>

<RowIndicatorColumn Visible="False">

<HeaderStyle Width="20px" />

</RowIndicatorColumn>

<Columns>

<rad:GridBoundColumn DataField="XREF_MAP_ID" HeaderText="Xref Map ID"

SortExpression="XREF_MAP_ID" UniqueName="XREF_MAP_ID" ReadOnly="True" Visible="False">

</rad:GridBoundColumn>

<rad:GridBoundColumn DataField="XREF_MAP_KEY" HeaderText="Xref Map Key"

SortExpression="XREF_MAP_KEY" UniqueName="XREF_MAP_KEY" >

</rad:GridBoundColumn>

<rad:GridBoundColumn DataField="XREF_MAP_DESCRIPTION" HeaderText="Xref Map Description"

SortExpression="XREF_MAP_DESCRIPTION" UniqueName="XREF_MAP_DESCRIPTION" >

</rad:GridBoundColumn>

<rad:GridBoundColumn DataField="GROUP_NAME" HeaderText="Group"

SortExpression="GROUP_NAME" UniqueName="GROUP_NAME" ReadOnly="True">

</rad:GridBoundColumn>

<rad:GridBoundColumn DataField="IN_DATATYPE" HeaderText="In Data Type"

SortExpression="IN_DATATYPE" UniqueName="IN_DATATYPE" >

</rad:GridBoundColumn>

<rad:GridBoundColumn DataField="OUT_DATATYPE" HeaderText="Out Data Type"

SortExpression="OUT_DATATYPE" UniqueName="OUT_DATATYPE" >

</rad:GridBoundColumn>

<rad:GridCheckBoxColumn DataField="MULTIPLE_ROW_RESULT_BOOL" HeaderText="Multiple Row Result" UniqueName="MULTIPLE_ROW_RESULT">

</rad:GridCheckBoxColumn>

<rad:GridBoundColumn DataField="ATTRIBUTE01_DESCRIPTION" HeaderText="Attribute 01 Description"

SortExpression="ATTRIBUTE01_DESCRIPTION" UniqueName="ATTRIBUTE01_DESCRIPTION" ReadOnly="True" Visible="False">

</rad:GridBoundColumn>

<rad:GridBoundColumn DataField="ATTRIBUTE02_DESCRIPTION" HeaderText="Attribute 02 Description"

SortExpression="ATTRIBUTE02_DESCRIPTION" UniqueName="ATTRIBUTE02_DESCRIPTION" ReadOnly="True" Visible="False">

</rad:GridBoundColumn>

<rad:GridBoundColumn DataField="ATTRIBUTE03_DESCRIPTION" HeaderText="Attribute 03 Description"

SortExpression="ATTRIBUTE03_DESCRIPTION" UniqueName="ATTRIBUTE03_DESCRIPTION" ReadOnly="True" Visible="False">

</rad:GridBoundColumn>

<rad:GridBoundColumn DataField="ATTRIBUTE04_DESCRIPTION" HeaderText="Attribute 04 Description"

SortExpression="ATTRIBUTE04_DESCRIPTION" UniqueName="ATTRIBUTE04_DESCRIPTION" ReadOnly="True" Visible="False">

</rad:GridBoundColumn>

<rad:GridBoundColumn DataField="ATTRIBUTE05_DESCRIPTION" HeaderText="Attribute 05 Description"

SortExpression="ATTRIBUTE05_DESCRIPTION" UniqueName="ATTRIBUTE05_DESCRIPTION" ReadOnly="True" Visible="False">

</rad:GridBoundColumn>

<rad:GridBoundColumn DataField="DATE_CREATED" DataType="System.DateTime" HeaderText="DATE_CREATED"

SortExpression="DATE_CREATED" UniqueName="DATE_CREATED" ReadOnly="True" Visible="False">

</rad:GridBoundColumn>

<rad:GridBoundColumn DataField="DATE_UPDATED" DataType="System.DateTime" HeaderText="DATE_UPDATED"

SortExpression="DATE_UPDATED" UniqueName="DATE_UPDATED" ReadOnly="True" Visible="False">

</rad:GridBoundColumn>

<rad:GridEditCommandColumn ShowSortIcon="False">

</rad:GridEditCommandColumn>

<rad:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column" ShowSortIcon="False">

</rad:GridButtonColumn>

</Columns>

<EditFormSettings EditFormType="Template">

<FormTemplate>

<table id="Table2" width="100%" border="1" rules="none"

style="border-collapse: collapse;background:white;">

<tr>

<td>

<asp:Label ID="Label7" runat="server" Text="Xref Map Key: "> </asp:Label>

</td>

<td>

<asp:TextBox ID="XrefMapKey" Text='<%# Bind( "XREF_MAP_KEY") %>' runat="server" Visible=true

Rows="5" Columns="40" TabIndex="5">

</asp:TextBox>

<asp:RequiredFieldValidator id="XrefMapKeyRequiredFieldValidator"

ControlToValidate="XrefMapKey"

Display="Static"

ErrorMessage="Required"

runat="server"/>

</td>

</tr>

<tr>

<td>

<asp:Label ID="MessageLabel" runat="server" Text="Xref Map Description: "> </asp:Label>

</td>

<td>

<asp:TextBox ID="XrefMapDescription" Text='<%# Bind( "XREF_MAP_DESCRIPTION") %>' runat="server"

Rows="5" Columns="40" TabIndex="5">

</asp:TextBox>

<asp:RequiredFieldValidator id="XrefMapDescriptionRequiredFieldValidator"

ControlToValidate="XrefMapDescription"

Display="Static"

ErrorMessage="Required"

runat="server"/>

</td>

</tr>

<tr>

<td>

<asp:Label ID="Label3" runat="server" Text="In Data Type: "> </asp:Label>

</td>

<td>

<asp:DropDownList ID="Group" runat="server" DataTextField="GROUP_NAME" DataValueField="GROUP_ID"

SelectedValue='<%# Bind("GROUP_ID") %>' DataSourceID="ODS_GROUP_SqlDataSource" TabIndex="7" AppendDataBoundItems="True">

</asp:DropDownList>

</td>

</tr>

<tr>

<tr>

<td>

<asp:Label ID="Label1" runat="server" Text="In Data Type: "> </asp:Label>

</td>

<td>

<asp:DropDownList ID="InDataType" runat="server" DataTextField="IN_DATATYPE"

SelectedValue='<%# Bind("IN_DATATYPE") %>' TabIndex="7" AppendDataBoundItems="True">

<asp:ListItem>DATE</asp:ListItem>

<asp:ListItem>CHAR</asp:ListItem>

<asp:ListItem>NUMBER</asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:DropDownList>

</td>

</tr>

<tr>

<td>

<asp:Label ID="Label2" runat="server" Text="Out Data Type: "> </asp:Label>

</td>

<td>

<asp:DropDownList ID="OutDataType" runat="server" DataTextField="OUT_DATATYPE"

SelectedValue='<%# Bind("OUT_DATATYPE") %>' TabIndex="7" AppendDataBoundItems="True">

<asp:ListItem>DATE</asp:ListItem>

<asp:ListItem>CHAR</asp:ListItem>

<asp:ListItem>NUMBER</asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:DropDownList>

</td>

</tr>

<tr>

<td>

<asp:Label ID="AvailableLabel" runat="server" Text="Multiple Row Result: "> </asp:Label>

</td>

<td>

<asp:Checkbox ID="MultipleRowResult" Checked='<%# GetCheckboxBool(Eval("MULTIPLE_ROW_RESULT_BOOL") as string) %>' runat="server"

TabIndex="4">

</asp:Checkbox>

<asp:TextBox ID="DateUpdated" Text='<%# Bind( "DATE_UPDATED") %>' runat="server" Visible=false

Rows="5" Columns="40" >

</asp:TextBox>

<asp:TextBox ID="Atttribute01Description" Text='<%# Bind( "ATTRIBUTE01_DESCRIPTION") %>' runat="server" Visible=false

Rows="5" Columns="40" >

</asp:TextBox>

<asp:TextBox ID="Atttribute02Description" Text='<%# Bind( "ATTRIBUTE02_DESCRIPTION") %>' runat="server" Visible=false

Rows="5" Columns="40" >

</asp:TextBox>

<asp:TextBox ID="Atttribute03Description" Text='<%# Bind( "ATTRIBUTE03_DESCRIPTION") %>' runat="server" Visible=false

Rows="5" Columns="40" >

</asp:TextBox>

<asp:TextBox ID="Atttribute04Description" Text='<%# Bind( "ATTRIBUTE04_DESCRIPTION") %>' runat="server" Visible=false

Rows="5" Columns="40" >

</asp:TextBox>

<asp:TextBox ID="Atttribute05Description" Text='<%# Bind( "ATTRIBUTE05_DESCRIPTION") %>' runat="server" Visible=false

Rows="5" Columns="40" >

</asp:TextBox>

</tr>

<tr>

<td align="right" colspan="2">

<td>

<asp:Button ID="Button1" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'

runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>

</asp:Button>

&nbsp;

<

asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"

CommandName

="Cancel"></asp:Button></td>

</tr>

</table>

</FormTemplate>

</EditFormSettings>

<HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"

Font-Underline="False" HorizontalAlign="Center" Wrap="True" />

<PagerStyle Position="TopAndBottom" />

</MasterTableView>

<PagerStyle Mode="NextPrevAndNumeric" Position="TopAndBottom" />

<ExportSettings FileName="EventDashboard">

</ExportSettings>

</rad:RadGrid>

<asp:SqlDataSource ID="ODS_GROUP_SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ODSConn %>"

ProviderName="<%$ ConnectionStrings:ODSConn.ProviderName %>" SelectCommand="SELECT GROUP_ID, GROUP_NAME FROM ODS_GROUP&#13;&#10;UNION&#13;&#10;SELECT null, '' FROM ODS_GROUP">

</asp:SqlDataSource>

<br />

 

</

asp:Content>

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 22 May 2008, 05:22 AM
Hi Darren,

Go through the following help article.
Extracting primary key value for parent item in hierarchy on Update/Insert

Shinu.


Tags
Grid
Asked by
Darren
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or