Hidden column in Details Table value is not retrieved

4 posts, 0 answers
  1. Hash
    Hash avatar
    4 posts
    Member since:
    Oct 2015

    Posted 03 Jan Link to this post

    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

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1741 posts

    Posted 06 Jan Link to this post

    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.
  3. Hash
    Hash avatar
    4 posts
    Member since:
    Oct 2015

    Posted 06 Jan in reply to Viktor Tachev Link to this post

    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

     

     

  4. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2067 posts

    Posted 12 Jan Link to this post

    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.
Back to Top