Hello,
I have a RadGrid in which I may need to hide a column in the detail tables of a Hierarchical table depending on the configuration of the user logged into the system. I cannot determine how to do this since I am already doing some customization for a vertical scrollbar in the detail tables. I am attempting to hide the UnitOfMeasure column.
Below are the designer and code-behind snippets for the table.
Designer:
Code-Behind:
Your assistance is greatly appreciated.
Thanks
I have a RadGrid in which I may need to hide a column in the detail tables of a Hierarchical table depending on the configuration of the user logged into the system. I cannot determine how to do this since I am already doing some customization for a vertical scrollbar in the detail tables. I am attempting to hide the UnitOfMeasure column.
Below are the designer and code-behind snippets for the table.
Designer:
<div> <telerik:RadGrid ID="RadGridOrderStatus" runat="server" AutoGenerateColumns="false" PageSize="10" AllowSorting="True" AllowPaging="true" Skin="Simple" CssClass="RegistrationFieldStyle" HeaderStyle-CssClass="RegistrationFieldStyle" Width="90%" HorizontalAlign="Left" ItemStyle-Wrap="false" OnItemCreated="RadGridOrderStatus_ItemCreated" OnPreRender="RadGridOrderStatus_PreRender" OnNeedDataSource="RadGridOrderStatus_NeedDataSource" OnItemDataBound="RadGridOrderStatus_ItemDataBound" OnDetailTableDataBind="RadGridOrderStatus_DetailTableDataBind"> <PagerStyle Mode="NumericPages" /> <ClientSettings> <Scrolling AllowScroll="true" UseStaticHeaders="true" /> </ClientSettings> <MasterTableView TableLayout="Fixed" AllowMultiColumnSorting="true" DataKeyNames="OrderNumber" Name="ORDER" ShowFooter="false" HierarchyLoadMode="Client" PagerStyle-AlwaysVisible="true" HorizontalAlign="Left" > <DetailTables> <telerik:GridTableView DataKeyNames="OrderNumber" runat="server" Width="100%" Name="ORDERDETAIL"> <ParentTableRelation> <telerik:GridRelationFields DetailKeyField="OrderNumber" MasterKeyField="OrderNumber" /> </ParentTableRelation> <NoRecordsTemplate> <asp:Label ID="lblMsg" runat="server" Text="No Order Detail Records Found"></asp:Label> </NoRecordsTemplate> <Columns> <telerik:GridBoundColumn HeaderText="NDC" HeaderButtonType="TextButton" DataField="NDCNumber" /> <telerik:GridBoundColumn HeaderText="Description" HeaderButtonType="TextButton" DataField="Description" /> <telerik:GridBoundColumn HeaderText="Unit Of Measure" HeaderButtonType="TextButton" DataField="UnitOfMeasure" /> <telerik:GridBoundColumn HeaderText="Requested Quantity" HeaderButtonType="TextButton" DataField="RequestedQty" /> <telerik:GridBoundColumn HeaderText="Shipped Quantity" HeaderButtonType="TextButton" DataField="ShippedQty" /> <telerik:GridBoundColumn HeaderText="Ship Date" HeaderButtonType="TextButton" DataField="ShipDate" DataFormatString="{0:MM/dd/yyyy hh:mm tt}" /> <telerik:GridHyperLinkColumn HeaderText="Tracking Number" HeaderButtonType="TextButton" DataTextField="Shipment.WaybillNumber" DataTextFormatString="{0}" DataNavigateUrlFields="Shipment.WaybillNumberCarrierUrl" DataNavigateUrlFormatString="{0}" Target="_blank" /> <telerik:GridBoundColumn HeaderText="Status" HeaderButtonType="TextButton" DataField="Shipment.Status" /> </Columns> </telerik:GridTableView> </DetailTables> <Columns> <telerik:GridBoundColumn HeaderText="Order Date" HeaderButtonType="TextButton" DataField="OrderDate" DataFormatString="{0:MM/dd/yyyy hh:mm tt}" HeaderStyle-Width="120px" ItemStyle-HorizontalAlign="Left" /> <telerik:GridBoundColumn HeaderText="Transaction Number" HeaderButtonType="TextButton" DataField="OrderNumber" HeaderStyle-Width="80px" ItemStyle-HorizontalAlign="Left" /> <telerik:GridTemplateColumn HeaderText="Ordered By" HeaderButtonType="TextButton" HeaderStyle-Width="100px" ItemStyle-HorizontalAlign="Left"> <ItemTemplate> <asp:Label ID="ContactName" runat="server" /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridBoundColumn HeaderText="Address" HeaderButtonType="TextButton" DataField="ShipToAddress.FullBlockAddress" HeaderStyle-Width="200px" ItemStyle-HorizontalAlign="Left" /> <telerik:GridBoundColumn HeaderText="Status" HeaderButtonType="TextButton" DataField="OrderStatus" HeaderStyle-Width="100px" ItemStyle-HorizontalAlign="Left" /> </Columns> </MasterTableView> </telerik:RadGrid> </div> Code-Behind:
#region RadGridOrderStatus_DetailTableDataBind protected void RadGridOrderStatus_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e) { GridDataItem orderItem = e.DetailTableView.ParentItem; if (e.DetailTableView.Name.ToUpper() == "ORDERDETAIL" && orderItem.DataItem is Order) { Order parentOrder = (Order)orderItem.DataItem; e.DetailTableView.DataSource = parentOrder.Products; } } #endregion #region RadGridOrderStatus_ItemCreated protected void RadGridOrderStatus_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridNestedViewItem) { GridNestedViewItem nestedItem = e.Item as GridNestedViewItem; nestedItem.NestedViewCell.PreRender +=new EventHandler(NestedViewCell_PreRender); } } protected void NestedViewCell_PreRender(object sender, EventArgs e) { ((Control)sender).Controls[0].SetRenderMethodDelegate(new RenderMethod(this.NestedViewTable_Render)); } protected void NestedViewTable_Render(HtmlTextWriter writer, Control control) { control.SetRenderMethodDelegate(null); writer.Write("<div style='height: 100%; overflow: scroll;'>"); control.RenderControl(writer); writer.Write("</div>"); } #endregion #region RadGridOrderStatus_ItemDataBound protected void RadGridOrderStatus_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem item = (GridDataItem)e.Item; if (e.Item.DataItem is Order) { Order parentOrder = (Order)e.Item.DataItem; Label contactName = (Label)e.Item.FindControl("ContactName"); switch (LocalSettings.CurrentUserProfile.RegistrationType.RegistrationTypeCode) { case EnumRegistrationType.HCP: case EnumRegistrationType.PHARMACIST: contactName.Text = parentOrder.ContactFirstName + " " + parentOrder.ContactLastName; break; } } } } #endregion #region RadGridOrderStatus_NeedDataSource protected void RadGridOrderStatus_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { RadGridOrderStatus.DataSource = LocalSettings.CurrentOrderSearchResponse.Orders; } #endregion Your assistance is greatly appreciated.
Thanks