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

how to get the hidden column value

8 Answers 2574 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kranthi
Top achievements
Rank 1
Kranthi asked on 06 Jul 2012, 02:54 PM
Hi All

i have a requirement to get the hidden column value for the rows which checkbox has been selected, can anyone come up with a good solution to complete this thing  may be client side or server side ... 

my rad grid 

            <telerik:RadGrid ID="M" runat="server" Width="99%" AllowPaging="True" EnableViewState="False"
                GridLines="None" meta:resourcekey="MResource1" AllowFilteringByColumn="true"
                OnInit="GridControl_Init" EnableLinqExpressions="false" 
                EnableEmbeddedSkins="false" AutoGenerateColumns="False">
                <HeaderContextMenu EnableEmbeddedSkins="True">
                </HeaderContextMenu>
                <FilterMenu Skin="Nediso" EnableEmbeddedSkins="false">
                </FilterMenu>
                <PagerStyle Mode="NextPrevAndNumeric" Position="TopAndBottom" AlwaysVisible="true" />
                <MasterTableView Width="100%" EnableViewState="False" AllowFilteringByColumn="true">
                   <Columns>  


                   <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn" AllowFiltering="false">
                   <HeaderStyle Width="3%" HorizontalAlign="Justify" />
                    <ItemStyle Width="3%" HorizontalAlign="Justify" />
                            <HeaderTemplate>
                             <asp:CheckBox id="headerChkbox"  runat="server" onclick="SelectAll(this)"></asp:CheckBox>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox id="CheckBox1" runat="server"></asp:CheckBox>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                   
                     <telerik:GridBoundColumn DataField="TOKEN" Visible="false" UniqueName="TOKEN" ReadOnly="true" >
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="FIRST NAME" HeaderText="FIRST NAME" UniqueName="FIRST NAME">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="LAST NAME" HeaderText="LAST NAME" UniqueName="LAST NAME">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="STATUS" HeaderText="STATUS" UniqueName="STATUS">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="DESIGNATION" HeaderText="DESIGNATION" UniqueName="DESIGNATION">
                    </telerik:GridBoundColumn>
                    </Columns>
                    <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" Position="TopAndBottom" />
                    
                </MasterTableView>
                <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" EnableRowHoverStyle="True">
                    <Resizing AllowColumnResize="True" />
                    <Selecting AllowRowSelect="True" />                    
                    <ClientEvents OnFilterMenuShowing="OnFilterMenuShowing"></ClientEvents> 
                    </ClientSettings>
                <FilterMenu EnableTheming="True">
                    <CollapseAnimation Type="None" />
                    <ExpandAnimation Type="None" />
                </FilterMenu>
            </telerik:RadGrid>

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Jul 2012, 09:26 AM
Hello,

One suggestion is you can set the Display property of the column as false and then get the column value. Try the following javascript to acess hidden column value.
aspx:
<telerik:GridBoundColumn UniqueName="EmployeeID" Display="false"  DataField="EmployeeID" HeaderText="EmployeeID">
</telerik:GridBoundColumn>
JS:
function check() {
 var grid = $find("<%=RadGrid1.ClientID %>");
 var masterTable = grid.get_masterTableView();
 var row = masterTable.get_dataItems()[0];
 var cell = masterTable.getCellByColumnUniqueName(row, "TOKEN");
 alert(cell.innerHTML);
}

Thanks,
Shinu.
0
Kostadin
Telerik team
answered on 09 Jul 2012, 11:50 AM
Hello Kranthi,

You can also do it by leaving the Visible property to false. For this purpose you should add the following javascript:

function RowSelected(sender, eventArgs) {
            
            var grid = sender;
            var MasterTable = grid.get_masterTableView();
            var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
            var cell = row.getDataKeyValue("TOKEN");
            //here cell.innerHTML holds the value of the cell  
        }

You should also add ClientDataKeyNames property in MasterTableView.

<MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource1" ClientDataKeyNames="TOKEN">

You will find more information here: http://www.telerik.com/help/aspnet-ajax/grid-extract-key-values-client-side.html

All the best,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Adam
Top achievements
Rank 1
answered on 06 Mar 2014, 05:26 AM
How can I do this server-side..??  I have a number of hidden fields..

I can't seem to get the text value other than "&nbsp;"

I've just upgraded from version 2011.x to 2013.3.1324.45..  my previous code no longer seems to work as expected. :

1.For Each i As GridDataItem In grdItems.MasterTableView.GetSelectedItems()
2.  If i.Selected Then
3.    Dim iVal As GridDataItem = i
4.    Dim IDVal as string = iVal("MER_ItemSummaryID").Text
5. 
6.  end if
7.next

I've set the DataKeyNames value for the MasterTableView and can get the value using :
iVal.KeyValues

This returns : "{MER_ItemSummaryID:"21694"}"

I thought there might be a nicer way to retrieve them than parsing a text value.

Thanks

0
Adam
Top achievements
Rank 1
answered on 06 Mar 2014, 05:38 AM
Sorry..  I hate it when you search for hours for a solution, you end up finally just posting to a forum like this one or SO, then literally 5 minutes later find the solution you require..

I just changed my code slightly to the following:

For Each i As GridDataItem In grdItems.MasterTableView.GetSelectedItems()
    If i.Selected Then
        Dim iVal As GridDataItem = i
        Dim IDVal as string = iVal.GetDataKeyValue("MER_ItemSummaryID").ToString()
    End If
Next


0
Princy
Top achievements
Rank 2
answered on 06 Mar 2014, 06:14 AM
Hi Adam,

If you have hidden columns for your grid, you can access them in the code-behind either through DataKeyValue or if you set the Display as false you may access the columns in server side. Please take a look at the below code.

ASPX:
<MasterTableView DataKeyNames="OrderID">
 <Columns>
  <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" Display="false" />  
 </Columns>

VB:
If TypeOf e.Item Is GridDataItem Then
    Dim items As GridDataItem = DirectCast(e.Item, GridDataItem)
    Dim id As String = items.GetDataKeyValue("OrderID").ToString()
    Dim value As String = items("ShipCIty").Text
End If

Thanks,
Princy
0
Amjad
Top achievements
Rank 1
answered on 23 Nov 2014, 10:40 AM
I have this problem that when  I get the hidden field value it returns &nbsp; when its empty.

how can I get around this issue?

please note that I can put if statement to avoid this but I need better solution
0
Kostadin
Telerik team
answered on 26 Nov 2014, 01:28 PM
Hi Amjad,

Note that when a columns is hidden by setting Visible to false it will set &nbsp; text to its cell. I am afraid if you need to remove it you have to manually do that on ItemDataBound event handler by checking the cell text.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Christophorus Donny
Top achievements
Rank 1
answered on 24 Aug 2017, 06:50 AM
Hi
don't use Visible="false" on your GridBoundColumn/GridNumericColumn.
try this to hidden your collumn and still get the value :
RadGrid1.MasterTableView.GetColumn("UniqueName").Display = False


Thanks,
Hsn
Tags
Grid
Asked by
Kranthi
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kostadin
Telerik team
Adam
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Amjad
Top achievements
Rank 1
Christophorus Donny
Top achievements
Rank 1
Share this question
or