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

[Solved] How to I access the GridTemplateColumn of the RadGrid in the Codebehind?

4 Answers 643 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vinix
Top achievements
Rank 1
Vinix asked on 13 May 2008, 05:10 AM

How to I access the GridTemplateColumn of the RadGrid in the Codebehind?

I have a RadGrid as following.

How to I access the GridTemplateColumn of the RadGrid in the Codebehind?

Many thanks for your replying.


<telerik:RadGrid ID="RadGrid_Category" runat="server" AllowSorting="True" GridLines="None" 
                                    Skin="Telerik" Width="100%" Height="360" OnSelectedIndexChanged="RadGrid_Category_SelectedIndexChanged" 
                                    DataKeyNames="CategoryId" DataSourceID="SqlDataSource_Category" OnItemDataBound="RadGrid_Category_ItemDataBound">  
                                    <ExportSettings> 
                                        <Pdf FontType="Subset" PaperSize="Letter" /> 
                                        <Excel Format="Html" /> 
                                        <Csv ColumnDelimiter="Comma" RowDelimiter="NewLine" /> 
                                    </ExportSettings> 
                                    <MasterTableView CommandItemDisplay="None" CurrentResetPageIndexAction="SetPageIndexToFirst" 
                                        Dir="LTR" Frame="Border" TableLayout="Auto" AutoGenerateColumns="False" DataSourceID="SqlDataSource_Category" 
                                        DataKeyNames="CategoryId">  
                                        <RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
                                            Visible="False">  
                                            <HeaderStyle Width="20px" /> 
                                        </RowIndicatorColumn> 
                                        <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" 
                                            Resizable="False" Visible="False">  
                                            <HeaderStyle Width="20px" /> 
                                        </ExpandCollapseColumn> 
                                        <EditFormSettings> 
                                            <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType">  
                                            </EditColumn> 
                                        </EditFormSettings> 
                                        <Columns> 
                                            <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="CategoryName" 
                                                FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="分類名稱" 
                                                SortExpression="CategoryName" UniqueName="CategoryName">  
                                                <HeaderStyle /> 
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="CategoryId" 
                                                FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="CategoryId" 
                                                SortExpression="CategoryId" UniqueName="CategoryId" Display="False">  
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridTemplateColumn HeaderText="編輯" UniqueName="TemplateColumn">  
                                                <ItemTemplate> 
                                                    <asp:ImageButton ID="ImageButton_Edit" runat="server" ImageUrl="/EditorPr.gif" OnClientClick="window.radopen('EditCategory.aspx', 'EditCategory'); return false;" /> 
                                                </ItemTemplate> 
                                            </telerik:GridTemplateColumn> 
                                        </Columns> 
                                    </MasterTableView> 
                                    <ClientSettings EnablePostBackOnRowClick="True">  
                                        <Selecting AllowRowSelect="True" /> 
                                        <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
                                    </ClientSettings> 
                                </telerik:RadGrid> 

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 13 May 2008, 05:57 AM
Hi Liu Pei-Sen,

You can access any column using its ColumnUniqueName property. Try the following code snippet to access the ImageButton in the ItemTemplate of a GridTemplateColumn.

CS:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
          
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            ImageButton imgbtn = (ImageButton)item["TemplateColumn"].FindControl("ImageButton_Edit");  
 
        }  
   } 


Hope this helps..
Princy.
0
Vinix
Top achievements
Rank 1
answered on 14 May 2008, 01:23 AM
Many thanks for your replying.
0
Shinu
Top achievements
Rank 2
answered on 14 May 2008, 05:11 AM
Hi,

You may also be interested to have a look at the following help articles.

Accessing cells and rows
Using columns

Shinu.
0
Vinix
Top achievements
Rank 1
answered on 14 May 2008, 06:24 AM
Thank you very much.
You help me a lot.
Tags
Grid
Asked by
Vinix
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Vinix
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or