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

Hidden column in Details Table value is not retrieved

3 Answers 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hash
Top achievements
Rank 1
Hash asked on 03 Jan 2017, 10:49 AM

Hi 

I am trying to reterive a value of hidden column (OrderDate) in details table from back end and the value I am getting is  

Please note that I am using Telerik version 2016.1.225.45 and the below code is in my web.config

<add key="BindGridInvisibleColumns" value="true"/>

 

ASPX Code:

<telerik:RadGrid Skin="Office2007" ID="RadGrid1" runat="server" ShowStatusBar="true" AutoGenerateColumns="False"
                           PageSize="7" AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True" CellPadding="1"
                           OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand"
                           OnPreRender="RadGrid1_PreRender" Style="padding: 3px; margin: 3px;">
                           <HeaderStyle CssClass="RadGridHeader" />                  
                           <MasterTableView Name="master" DataKeyNames="CustomerID" AutoGenerateColumns="false" NoMasterRecordsText="No records meet the search criteria.">
                               <DetailTables>
                                   <telerik:GridTableView AllowPaging="false" DataMember="OrderDrillDown" DataKeyNames="OrderID,CustomerID" runat="server"
                                       Name="Orders" Width="100%" AllowMultiRowSelection="false" CommandItemDisplay="Top" NoDetailRecordsText="No Exclusions.">
                                       <Columns>
                                           <telerik:GridBoundColumn SortExpression="OrderID" HeaderText="OrderID" HeaderButtonType="TextButton"
                                               DataField="OrderID">
                                           </telerik:GridBoundColumn>
                                           <telerik:GridBoundColumn SortExpression="OrderDate" HeaderText="Date Ordered" HeaderButtonType="TextButton"
                                               DataField="OrderDate" UniqueName="OrderDate" DataFormatString="{0:D}" Visible="false">
                                           </telerik:GridBoundColumn>
                                           <telerik:GridBoundColumn SortExpression="Freight" HeaderText="Freight" HeaderButtonType="TextButton"
                                               DataField="Freight" UniqueName="Freight">
                                           </telerik:GridBoundColumn>
 
                                           <telerik:GridButtonColumn ButtonType="LinkButton" UniqueName="Delete" Text="Delete"
                                               CommandName="Delete">
                                               <ItemStyle HorizontalAlign="Center" Width="10%" />
                                           </telerik:GridButtonColumn>
 
                                       </Columns>
                                   </telerik:GridTableView>
                               </DetailTables>
                               <Columns>
                                   <telerik:GridBoundColumn SortExpression="CustomerID" HeaderText="CustomerID" HeaderButtonType="TextButton"
                                       DataField="CustomerID">
                                   </telerik:GridBoundColumn>
                                   <telerik:GridBoundColumn SortExpression="ContactName" HeaderText="Contact Name" HeaderButtonType="TextButton"
                                       DataField="ContactName" Visible="false">
                                   </telerik:GridBoundColumn>
                                   <telerik:GridBoundColumn SortExpression="CompanyName" HeaderText="Company" HeaderButtonType="TextButton"
                                       DataField="CompanyName">
                                   </telerik:GridBoundColumn>
 
                                   <telerik:GridButtonColumn ButtonType="LinkButton" UniqueName="DeleteHac" Text="Delete"
                                       CommandName="DeleteHac">
                                       <ItemStyle HorizontalAlign="Center" Width="10%" />
                                   </telerik:GridButtonColumn>
                               </Columns>
                           </MasterTableView>
                           <PagerStyle Mode="NextPrevAndNumeric" />
                           <ClientSettings EnableRowHoverStyle="True" EnablePostBackOnRowClick="false">
                               <Selecting AllowRowSelect="false" />
 
                           </ClientSettings>
                       </telerik:RadGrid>

 

 

Code behind:

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
       {
           GridDataItem selectedItem = (GridDataItem)e.Item;
 
           if (e.CommandName == "Delete")
           {
               var check = selectedItem["OrderDate"].Text;
           }
           else if (e.CommandName == "DeleteHac")
           {
                var check1 = selectedItem["ContactName"].Text;
           }
       }

 

When trying to get OrderDate value I am getting &nbsp; as value but I am getting the same value when the columns visiblity is set to true. 

I can confirm this was working fine when the Telerik UI version was 2015.1.401.45

Also, I found a workaround for this by using Display instead of Visible, but do you think that is the only workaround or is this a known bug?

Thanks

Hazersha

3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 06 Jan 2017, 09:13 AM
Hello Hash,

When a column is hidden via the Visible property it will not be rendered at all. This is why you are getting the value from the column as "&nbsp;".

If you would like to hide a column in the Grid and still use the values from it you should use the Display property instead.

<telerik:GridBoundColumn SortExpression="OrderDate" HeaderText="Date Ordered" HeaderButtonType="TextButton" DataField="OrderDate" UniqueName="OrderDate" DataFormatString="{0:D}" Display="false">


Alternatively you can add the OrderDate to the DataKeyNames collection and access if via GetDataKeyValue method. Please examine the article below that illustrates the approach in more detail.



Regards,
Viktor Tachev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Hash
Top achievements
Rank 1
answered on 06 Jan 2017, 09:35 AM

Many thanks for your reply. 

In the above example if you see ContractName is also visible set to false, but the value for this column is retrieved correctly. I assume that we are getting values for ContractName because it is in Master Table not Details Table 

Also, I have used the below code in web.config file. 

<add key="BindGridInvisibleColumns" value="true"/>

 

Please note that this was working fine when we were using Telerik Version 2015.1.401.45 and this happens only when we upgrade it to 2016.1.225.45.

I understand we can use Display instead of Visible, but just wanted to make sure that retrieving invisible columns value from the Details table in RadGrid was removed or a bug in latest Telerik version?

Thanks

Hazersha

 

 

0
Konstantin Dikov
Telerik team
answered on 12 Jan 2017, 12:01 PM
Hi Hash,

With the version that you are using the BindGridInvisibleColumns is not applied for the DetailTables and that bug is fixed in our latest version. Can you please upgrade to the latest and let us know if everything works correctly.

Looking forward to your reply.


Regards,
Konstantin Dikov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Hash
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Hash
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or