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

How to access deleting row column values from RadGrid?

1 Answer 242 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Indranath
Top achievements
Rank 1
Indranath asked on 02 Jun 2011, 02:24 AM
Hi Guys,

I am not able to access one of the column value from RadGrid when user click the delete icon. I am able to retrieve the primary key associated with that deleting row. My grid data coming from 2 different tables and one of the grid column indicate which table it is.

Following code retrieve the PK value:

GridDataItem item = (GridDataItem)e.Item; 

int ControlId = Convert.ToInt32(item.OwnerTableView.DataKeyValues[item.ItemIndex]["ControlID"]);

RadGrid template:
 

<

 

 

telerik:RadGrid ID="radCntDets" runat="server" GridLines="None" Width="938px"

 

 

 

AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"

 

OnNeedDataSource="radCntDets_OnNeedDataSource"

 

 

AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates ="True"

 

 

HorizontalAlign ="NotSet"

 

Font-Size ="Small"  OnItemUpdated ="radCntDets_ItemUpdated"

 

OnUpdateCommand ="radCntDets_UpdateCommand"

 

OnInsertCommand ="radCntDets_InsertCommand"

 

OnDeleteCommand="radCntDets_DeleteCommand">

 

<ClientSettings EnableRowHoverStyle="True">
<Scrolling AllowScroll="True" UseStaticHeaders="True"/>

 

</ClientSettings>

 

<MasterTableView GridLines="None" CommandItemDisplay="Top" DataKeyNames="ControlID" EditMode ="InPlace">

<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>

 

<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>

 

<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>

 

<Columns>

 

<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" ItemStyle-Width="100px" HeaderStyle-Width="100px">  

<HeaderStyle Width="100px"></HeaderStyle>

 

<ItemStyle Width="100px"></ItemStyle >

</telerik:GridEditCommandColumn

<telerik:GridButtonColumn ConfirmText="Delete this control?" ButtonType ="ImageButton"

 

CommandName="Delete" Text="Delete" UniqueName ="DeleteColumn1">

 

<HeaderStyle Width="20px"/>

 

<ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"/>

 

</telerik:GridButtonColumn>

 

<telerik:GridBoundColumn UniqueName="FirstName" HeaderText="First Name" DataField="FirstName" HeaderStyle-Width="100px" ItemStyle-Width="100px" 

<HeaderStyle Width="100px"></HeaderStyle>
<ItemStyle Width="100px"></ItemStyle>

 

</telerik:GridBoundColumn>

 

<telerik:GridBoundColumn UniqueName="LastName" HeaderText="Last Name" DataField="LastName" HeaderStyle-Width="100px" ItemStyle-Width="100px">

 

<HeaderStyle Width="100px"></HeaderStyle>

 

<ItemStyle Width="100px"></ItemStyle>

 

</telerik:GridBoundColumn>

 

<telerik:GridTemplateColumn UniqueName="ControlType" HeaderText="Control Type" ItemStyle-Width="100px" HeaderStyle-Width="100px">

 

<ItemTemplate>

 

<%

 

#DataBinder.Eval(Container.DataItem, "ControlType")%>

 

 

</ItemTemplate>

 

<InsertItemTemplate>

 

<telerik:RadComboBox runat="server" ID="radControlType" DataTextField="TypeName" Width="100px"

 

DataValueField="TypeName" SelectedValue='<%# Bind("ControlType") %> '  

DataSourceID="xmlContactType" Skin="Web20">

 

</telerik:RadComboBox>

 

</InsertItemTemplate>

 

<EditItemTemplate>

 

<asp:TextBox ID="txtControlType" runat="server" ReadOnly="true" CssClass="bodyText" Text='<%# Bind("ControlType") %>'></asp:TextBox>

 

</EditItemTemplate>

 

<ItemStyle Width="140px"></ItemStyle>

 

</telerik:GridTemplateColumn 
<telerik:GridTemplateColumn HeaderText="Email Address" UniqueName="EmailAddress" ItemStyle-Width="80px" HeaderStyle-Width

="80px">

 

<ItemTemplate>

 

<%

 

#DataBinder.Eval(Container.DataItem, "EmailAddress")%>  

</ItemTemplate>

 

<EditItemTemplate>

 

<asp:TextBox ID="txtEAddress" runat="server" Text='<%# Bind("EmailAddress") %>'></asp:TextBox>

 

</EditItemTemplate>

 

</telerik:GridTemplateColumn>

 

<telerik:GridBoundColumn UniqueName="PhoneNumber" HeaderText="Phone" DataField="PhoneNumber"

 

HeaderStyle-Width="90px" ItemStyle-Width="90px">

 

</telerik:GridBoundColumn 

<telerik:GridBoundColumn UniqueName="Role" HeaderText="Role" DataField="Role"

 

HeaderStyle-Width="70px" ItemStyle-Width="70px">

 

</telerik:GridBoundColumn 

<telerik:GridBoundColumn UniqueName="Notes" HeaderText="Notes" DataField="Notes"

 

HeaderStyle-Width="220px" ItemStyle-Width="220px">

 

<HeaderStyle Width="220px"></HeaderStyle 

<ItemStyle Width="220px"></ItemStyle 

</telerik:GridBoundColumn>

 

</Columns>

 

 

<EditFormSettings>

 

<EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn 

</EditFormSettings>

 

</MasterTableView>

 

<FilterMenu EnableImageSprites="False"></FilterMenu

<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu 

 

 

</telerik:RadGrid>
<asp:XmlDataSource ID="xmlContactType" runat="server" DataFile="~/XML/ControlTypes.xml"></asp:XmlDataSource>

Codebehind:

 

GridEditableItem

 

 

editedItem = e.Item as GridEditableItem ;

 

 

 

GridEditManager editMan = editedItem.EditManager;

 

 

string _cType = string.Empty;
foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)

 

 

{

 

 

 

if (column is IGridEditableColumn)

 

 

{

 

 

 

IGridEditableColumn editableCol = (column as IGridEditableColumn );

 

 

if (editableCol.IsEditable)

 

 

{

 

 

 

IGridColumnEditor

editor = editMan.GetColumnEditor(editableCol); -----> Error:Specified argument was out of the range of valid values.

 

if (editor is GridTemplateColumnEditor)

 

 

{

 

 

 

if (column.UniqueName.Equals("ControlType" ))

 

 

_cType = ((

 

 

 

TextBox)(((Telerik.Web.UI.GridColumnEditorBase)((editor as GridTemplateColumnEditor

))).ContainerControl).Controls[1]).Text;

}

 

}

 

}

 

}

Please advise me how to access the value of a template controlType in bold.

Thanks
Indra

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 07 Jun 2011, 01:37 PM
Hello Indranath,

 You can just call FindControl method of the cell for the template column to get the desired control inside:

foreach (var item in RadGrid1.MasterTableView.GetItems(new GridItemType[]{ GridItemType.EditItem}))
           {
               GridEditableItem editItem = item as GridEditableItem;
               if (editItem.IsInEditMode)
               {
                   RadComboBox combo= editItem["ControlType"].FindControl("radControlType") as RadComboBox;
               }
           }

Also note that the GridTemplateColumn does not have an InsertItemTemplate as you had specified in the code. If you need to have different appearances during insert and update you can use the approach specified in this help topic.


Regards,
Marin
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
Indranath
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or