Dear
I'm applying security by disable all controls with certain CssClass based on permission, for example I'm adding Insert CssClass to controls I want to disable or enable base on user role.
Now this is working great with RadGrid but unfortunately when using Detail/Hierarchy Grid within RadGrid I can't apply this logic, I don't know why, can you help me please?
ASPX:
CS (Logic):
I'm applying security by disable all controls with certain CssClass based on permission, for example I'm adding Insert CssClass to controls I want to disable or enable base on user role.
Now this is working great with RadGrid but unfortunately when using Detail/Hierarchy Grid within RadGrid I can't apply this logic, I don't know why, can you help me please?
ASPX:
<telerik:RadAjaxPanel ID="RadAjaxPanel" runat="server" LoadingPanelID="RadAjaxLoadingPanel" HorizontalAlign="NotSet"> <telerik:RadGrid ID="grdTransactions" runat="server" AllowPaging="True" CellSpacing="0" GridLines="None" AutoGenerateColumns="False" DataSourceID="odsEmployeeTrans" AllowFilteringByColumn="True" AllowSorting="True" ShowGroupPanel="True" EnableTheming="True"> <ClientSettings AllowDragToGroup="True"> <Scrolling AllowScroll="False" UseStaticHeaders="True" /> </ClientSettings> <ExportSettings> <Pdf PageTitle="Transactions" Author="WebTimeTel" Creator="WebTimeTel" PaperSize="A4"></Pdf> </ExportSettings> <MasterTableView AllowMultiColumnSorting="True" DataKeyNames="TransID" DataSourceID="odsEmployeeTrans" PageSize="50"> <DetailTables> <telerik:GridTableView runat="server" CommandItemDisplay="TopAndBottom" DataKeyNames="TaskID" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" DataSourceID="odsTasks" AllowFilteringByColumn="False" AllowSorting="False"> <ParentTableRelation> <telerik:GridRelationFields DetailKeyField="TransID" MasterKeyField="TransID"></telerik:GridRelationFields> </ParentTableRelation> <CommandItemSettings ExportToPdfText="Export to PDF" AddNewRecordText="Add New Task" /> <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True"> <HeaderStyle Width="20px" /> </RowIndicatorColumn> <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True"> <HeaderStyle Width="20px" /> </ExpandCollapseColumn> <CommandItemTemplate> <asp:LinkButton ID="lbtnAdd" runat="server" CssClass="Insert" CommandName="InitInsert" Visible='<%# !grdTransactions.MasterTableView.DetailTables[0].IsItemInserted %>'>Add new</asp:LinkButton> <asp:LinkButton ID="lbtnAddThis" runat="server" CssClass="Insert" CommandName="PerformInsert" Visible='<%# grdTransactions.MasterTableView.DetailTables[0].IsItemInserted %>'> Add this</asp:LinkButton> </CommandItemTemplate> <Columns> <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Edit" FilterControlAltText="Filter column column" ButtonCssClass="Update" UniqueName="Edit" HeaderStyle-Width="3%"> <HeaderStyle Width="3%" /> </telerik:GridButtonColumn> <telerik:GridTemplateColumn DataField="TaskType" FilterControlAltText="Filter TaskType column" HeaderText="Task Type" UniqueName="TaskType"> <EditItemTemplate> <telerik:RadComboBox ID="ddlTaskType" DataSourceID="odsTaskTypes" DataTextField="TaskTypeEn" DataValueField="TaskTypeId" SelectedValue='<%# Bind("TaskTypeId") %>' runat="server"></telerik:RadComboBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="TaskTypeLabel" runat="server" Text='<%# Eval("TaskType.TaskTypeEn") %>'></asp:Label> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridDateTimeColumn FilterControlAltText="Filter TimeFom column" HeaderText="Time From" UniqueName="TimeFrom" DataField="TimeFrom" PickerType="TimePicker" DataType="System.DateTime" DataFormatString="{0:hh:mm tt}"> </telerik:GridDateTimeColumn> <telerik:GridDateTimeColumn FilterControlAltText="Filter TimeTo column" HeaderText="Time To" UniqueName="TimeTo" DataField="TimeTo" PickerType="TimePicker" DataType="System.DateTime" DataFormatString="{0:hh:mm tt}"> </telerik:GridDateTimeColumn> <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmText="Are you sure?" FilterControlAltText="Filter column column" ImageUrl="~/images/delete.png" ButtonCssClass="Delete" UniqueName="Delete" HeaderStyle-Width="3%"> <HeaderStyle Width="3%" /> </telerik:GridButtonColumn> </Columns> <EditFormSettings> <EditColumn ButtonType="ImageButton" FilterControlAltText="Filter EditCommandColumn column"> </EditColumn> </EditFormSettings> <PagerStyle AlwaysVisible="True" /> </telerik:GridTableView> </DetailTables> <CommandItemSettings ExportToPdfText="Export to PDF" ShowExportToPdfButton="True" ShowAddNewRecordButton="False" ExportToCsvText="Export to CSV" ShowExportToCsvButton="True" /> <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True"> <HeaderStyle Width="20px" /> </RowIndicatorColumn> <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True"> <HeaderStyle Width="20px" /> </ExpandCollapseColumn> <Columns> <telerik:GridButtonColumn Text="Select" CommandName="Select" FilterControlAltText="Filter Images column" UniqueName="Select"> </telerik:GridButtonColumn> <telerik:GridBoundColumn DataField="TransID" FilterControlAltText="Filter TransID column" HeaderText="Trans#" UniqueName="TransID" AllowFiltering="False" Display="False"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlAltText="Filter EmployeeNumber column" HeaderText="Employee#" DataField="EmployeeNumber" UniqueName="EmployeeNumber"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlAltText="Filter EmployeeCode column" HeaderText="Employee Code" DataField="EmployeeCode" UniqueName="EmployeeCode"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlAltText="Filter EmployeeName column" HeaderText="Name" DataField="EmployeeName" UniqueName="EmployeeName"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlAltText="Filter DepartmentEn column" HeaderText="Department" DataField="EmployeeDepartmentEn" UniqueName="DepartmentEn"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlAltText="Filter DepartmentAr column" HeaderText="القسم" DataField="EmployeeDepartmentAr" UniqueName="DepartmentAr"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlAltText="Filter TransDate column" HeaderText="In Date" DataField="InDateTime" DataFormatString="{0:dd/MM/yyyy}" UniqueName="InDate" DataType="System.DateTime"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlAltText="Filter TransDate column" HeaderText="In Time" DataField="InDateTime" DataFormatString="{0:hh:mm tt}" UniqueName="InTime" DataType="System.DateTime"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlAltText="Filter TransTypeEn column" HeaderText="In Device" DataField="DeviceInName" UniqueName="InDeviceName"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="OutDateTime" FilterControlAltText="Filter Device column" HeaderText="Out Date" DataFormatString="{0:dd/MM/yyyy}" UniqueName="OutDate"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="OutDateTime" FilterControlAltText="Filter Device column" HeaderText="Out Time" DataFormatString="{0:hh:mm tt}" UniqueName="OutTime"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="DeviceOuName" FilterControlAltText="Filter OutDeviceName column" HeaderText="Out Device Name" UniqueName="OutDeviceName"> </telerik:GridBoundColumn> </Columns> <EditFormSettings> <EditColumn FilterControlAltText="Filter EditCommandColumn column"> </EditColumn> </EditFormSettings> <PagerStyle Position="Bottom" AlwaysVisible="True" Mode="NumericPages" /> </MasterTableView> <PagerStyle AlwaysVisible="True" Mode="NumericPages" /> <FilterMenu EnableImageSprites="False"> </FilterMenu> </telerik:RadGrid>protected override void OnLoad(EventArgs e){ base.OnLoad(e); if (Module != null) { StaticModule = Module; _staticUser = _user; if (!_groupRepository.IsUserAllowToView(Module, _user.UserID.Value)) throw new HttpException(401, "Unauthorized access"); var securedControls = Helpers.Methods.GetAllControls(this) .OfType<WebControl>() .Where(c => c.CssClass == "Insert" || c.CssClass == "Update"|| c.CssClass == "Delete"); if (!_groupRepository.IsUserAllowToInsert(Module, _user.UserID.Value)) { foreach (var control in securedControls.Where(c => c.CssClass == "Insert")) { control.Enabled = false; } } if (!_groupRepository.IsUserAllowToUpdate(Module, _user.UserID.Value)) { foreach (var control in securedControls.Where(c => c.CssClass == "Update")) { control.Enabled = false; } } if (!_groupRepository.IsUserAllowToDelete(Module, _user.UserID.Value)) { foreach (var control in securedControls.Where(c => c.CssClass == "Delete")) { control.Enabled = false; } } }}