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

Get value of GridTemplateColumn in selected row in Grid?

3 Answers 37 Views
This is a migrated thread and some comments may be shown as answers.
Jerald
Top achievements
Rank 1
Jerald asked on 10 Aug 2018, 03:29 PM

I need to retrieve the value of the docTitle GridTemplateColumn, but I'm not having any luck.  How can I modify my code to get the docTitle value of the selected row:

 

Here's the grid markup:

<telerik:RadGrid ID="rgVenDocs" runat="server" DataSourceID="sdsRgVenDocs" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True" ShowGroupPanel="True" Skin="Office2010Black" OnPreRender="rgVenDocs_PreRender" OnItemCommand="rgVenDocs_ItemCommand" OnSelectedIndexChanged="rgVenDocs_SelectedIndexChanged" ShowStatusBar="true" ViewStateMode="Enabled">
    <ClientSettings AllowDragToGroup="True" AllowColumnsReorder="True" ReorderColumnsOnClient="True" >
    </ClientSettings>
    <MasterTableView DataKeyNames="docIdPk" DataSourceID="sdsRgVenDocs" PagerStyle-AlwaysVisible="true">
        <Columns>
            <telerik:GridButtonColumn ButtonType="LinkButton" CommandName="Select" Text="Select"></telerik:GridButtonColumn>
            <telerik:GridBoundColumn DataField="docIdPk" ReadOnly="True" HeaderText="docIdPk" SortExpression="docIdPk" UniqueName="docIdPk" DataType="System.Int32" FilterControlAltText="Filter docIdPk column"></telerik:GridBoundColumn>                            
            <telerik:GridBoundColumn DataField="docFileName" HeaderText="docFileName" SortExpression="docFileName" UniqueName="docFileName" FilterControlAltText="Filter docFileName column"></telerik:GridBoundColumn>        
            <telerik:GridTemplateColumn DataField="docTitle" HeaderText="Document" UniqueName="docTitle" SortExpression="docTitle" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="true">
                <ItemTemplate>
                    <asp:LinkButton ID="lnkDownload" Text='<%# Eval("docTitle") %>' CommandArgument='<%# Eval("docPath") %>' runat="server" OnClick="lnkDownload_Click"></asp:LinkButton>              
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

 

Here's the SelectedIndexChanged code:

protected void rgVenDocs_SelectedIndexChanged(object sender, EventArgs e)
{  
    foreach (GridDataItem item in rgVenDocs.SelectedItems)
{  
doctitletest.Text = item["docTitle"].Text;
}
}

 

 

3 Answers, 1 is accepted

Sort by
0
Jerald
Top achievements
Rank 1
answered on 10 Aug 2018, 03:36 PM
I think what I'm looking for is along the same lines as the post located here ...https://www.telerik.com/forums/access-row-values-from-item-command
0
Jerald
Top achievements
Rank 1
answered on 10 Aug 2018, 03:37 PM
I think what I'm looking for is something similar to the following post:  https://www.telerik.com/forums/access-row-values-from-item-command
0
Jerald
Top achievements
Rank 1
answered on 10 Aug 2018, 05:39 PM

Nevermind, I got it.  I needed to find the control instead.

 

LinkButton lb = (LinkButton)item.FindControl("lnkDownload");
                doctitletest.Text = lb.Text;
Tags
Grid
Asked by
Jerald
Top achievements
Rank 1
Answers by
Jerald
Top achievements
Rank 1
Share this question
or