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

[Solved] getCellByColumnUniqueName with ItemTemplates

2 Answers 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jasper
Top achievements
Rank 1
Jasper asked on 06 May 2009, 12:45 PM
Hi,

I'm just evaluating the RadControls an trying to figure out how to get the value of a cell from a RadGrid if I use ItemTemplates.
I read this article from the manual but it doesn't work as espected.
This is my grid and JS code:

        function RowSelected(sender, eventArgs) { 
            var MasterTable = sender.get_masterTableView(); 
            var row = eventArgs.get_gridDataItem(); 
            alert(MasterTable.getCellByColumnUniqueName(row, "ID").innerHTML); 
        } 

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" GridLines="None" 
                Skin="Office2007" ShowHeader="False"
                <ClientSettings> 
                    <Selecting AllowRowSelect="True" /> 
                    <ClientEvents OnRowSelected="RowSelected" OnRowCreated="RowCreated" /> 
                </ClientSettings> 
                <MasterTableView AllowAutomaticUpdates="True" DataSourceID="SqlDataSource1" HorizontalAlign="Left"
                    <Columns> 
                        <telerik:GridTemplateColumn UniqueName="Other"
                            <ItemTemplate> 
                                <span style="display: block; float: left;"
                                    <%# Eval("by")%></span<span style="display: block; float: right;"
                                        <%# Eval("date")%></span
                                <br /> 
                                <span style="font-weight: bold;"
                                    <%# Eval("subject")%> 
                                </span> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                        <telerik:GridTemplateColumn UniqueName="ID"
                            <ItemTemplate> 
                                <%# Eval("ID")%> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                    </Columns> 
                </MasterTableView> 
            </telerik:RadGrid> 


I'm able to get the id, but the problem is, that all columns are displayed (I retrieve about 10 columns from DB while showing only 3) using the markup but I need to display a selection of them with a custom template and retrieving data of other columns which are not displayed (for instance ID).
If I define a new ItemTemplate after the closing <columns> tag the grid is displayed correctly but I cant access the id.




Cutting a long story short I'm looking for a clean and clientside way to access the content of specific cells which are not displayed.
I don't like something like <span style="display:none"> <%# Eval("ID")%></span> and MasterTable.getCellByColumnUniqueName(row, "Info").document.getElementByTagName('span')[int].innerHTML because this is a dirty workaround.

Any help is highly appreciated.

Kind regards Jay

2 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 07 May 2009, 05:40 AM
Hi Jasper,

To achieve the desired functionality, please refer to the following help topic:
Getting cell values for selected rows client side

Greetings,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jasper
Top achievements
Rank 1
answered on 12 May 2009, 01:05 PM
Well, I used the ClientDataKeyNames attribute and can now access it by using the GetDataKeyValue method.

Thx for help.
Tags
Grid
Asked by
Jasper
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Jasper
Top achievements
Rank 1
Share this question
or