Hi
Environment: RadControls for ASP.NET AJAX Q3 2009 / VS 2008 SP1/IE7/WINXP SP 2.
I would like to conditionally hide or disallow the Update in GridEditFormItem for certain users. For Example If the User is 'PR Manager', all add/update/edit/delete options will be available, for others Radgrid will be read only.
I can hide the command items template without any problem but the problem is when the Grid is in GridEditFormItem. Just can't refer the EditCommandColumn1 (null exception error occurs) or hide its update text.
Ideal solution will be if user is not 'PR Manager', only the cancel option will be available in GridEditFormItem. Below is my Radgrid and Radgrid_Item Command.
Any help will be appreciated...
Thanks
GC_0620
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if ((Session["SessionUserEmplCategory"].ToString().Trim() != "PR Manager")) |
| { |
| // This works... |
| if (e.Item is GridCommandItem) |
| { |
| GridCommandItem cmdItem = (GridCommandItem)e.Item; |
| LinkButton btnedit = (LinkButton)cmdItem.FindControl("btnEditSelected"); |
| btnedit.Visible = false; |
| LinkButton btnupdate = (LinkButton)cmdItem.FindControl("btnUpdateEdited"); |
| btnupdate.Visible = false; |
| LinkButton btnadd = (LinkButton)cmdItem.FindControl("BtnInitInsert"); |
| btnadd.Visible = false; |
| LinkButton btninsert = (LinkButton)cmdItem.FindControl("btnPerformInsert"); |
| btninsert.Visible = false; |
| LinkButton btndelete = (LinkButton)cmdItem.FindControl("BtnDelete"); |
| btndelete.Visible = false; |
| LinkButton btnCancel = (LinkButton)cmdItem.FindControl("btnCancel"); |
| btnCancel.Visible = false; |
| LinkButton btnRefresh = (LinkButton)cmdItem.FindControl("btnRefresh"); |
| btnRefresh.Visible = false; |
| } //// Can't Hide the EditCommandColumn or hide its Update text. |
| if (e.Item is GridEditFormItem && e.Item.IsInEditMode) |
| { |
| /// Allow only Cancel option if not 'PR Manager'
|
| GridEditFormItem EditFormcmdItem = (GridEditFormItem)e.Item; |
| EditFormcmdItem.FindControl("EditCommandColumn1").Visible = false; |
| } |
| } |
Rad Grid:
| <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" |
| AllowSorting="True" |
| ''' |
| '''" OnItemDataBound="RadGrid1_ItemDataBound"> |
| <MasterTableView DataKeyNames="ID" CommandItemDisplay="Top" Width="100%" Font-Size="11px"> |
| <CommandItemTemplate> |
| <div style="padding: 5px 5px;"> |
| Custom command item template |
| <asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditSelected" Visible='<%# RadGrid1.EditIndexes.Count == 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Edit.gif" />Edit selected</asp:LinkButton> |
| <asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Visible='<%# RadGrid1.EditIndexes.Count > 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Update.gif" />Update</asp:LinkButton> |
| <asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" Visible='<%# RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Cancel.gif" />Cancel editing</asp:LinkButton> |
| <asp:LinkButton ID="BtnInitInsert" runat="server" CommandName="InitInsert" Visible='<%# !RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/AddRecord.gif" />Add new</asp:LinkButton> |
| <asp:LinkButton ID="btnPerformInsert" runat="server" CommandName="PerformInsert" |
| Visible='<%# RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Insert.gif" /> Add this Attachment</asp:LinkButton> |
| <asp:LinkButton ID="BtnDelete" OnClientClick="javascript:return confirm('Delete all selected Attachments?')" |
| runat="server" CommandName="DeleteSelected"><img style="border:0px;vertical-align:middle;" alt="" src="Images/Delete.gif" />Delete selected Attachments</asp:LinkButton> |
| <asp:LinkButton ID="BtnView" runat="server" CommandName="EditSelected" Visible='<%# RadGrid1.EditIndexes.Count == 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Preview-icon.png" /> View selected</asp:LinkButton> |
| <asp:LinkButton ID="btnRefresh" runat="server" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="Images/Refresh.gif" />Refresh Attachment list</asp:LinkButton> |
| </div> |
| </CommandItemTemplate> |
| <Columns> |
| '''' '''' |
| </Columns> |
| <EditFormSettings> |
| <EditColumn InsertText="Insert" UpdateText="Update" UniqueName="EditCommandColumn1" // Allow only Cancel if user is not 'PR Manager' |
| CancelText="Cancel"> |
| </EditColumn> |
| <FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle> |
| </EditFormSettings> |
| </MasterTableView> |
| <ClientSettings> |
| <Selecting AllowRowSelect="True" /> |
| <ClientEvents OnCommand="gridCommand" /> |
| </ClientSettings> |
| </telerik:RadGrid> |