I have a grid that allows edit and delete buttons for some fields. Now, we're going to let non-admin users also see the same page, but want them to not be able to see the edit and delete buttons.
Any ideas where I should turn for that?
Any ideas where I should turn for that?
3 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 19 Jan 2009, 04:15 AM
Hello,
I suppose that you have a column bound to user. If so, Check out the following code to disable controls in the grid for particular users.
aspx:
cs:
Thanks
Princy.
I suppose that you have a column bound to user. If so, Check out the following code to disable controls in the grid for particular users.
aspx:
| <telerik:GridBoundColumn DataField="User" UniqueName="User" HeaderText="Users"></telerik:GridBoundColumn> |
| <telerik:GridTemplateColumn UniqueName="DeleteCol"> |
| <ItemTemplate> |
| <asp:Button ID="DeleteBu8tton" runat="server" Text="Delete" CommandName="Delete" /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn UniqueName="EditCol"> |
| <ItemTemplate> |
| <asp:Button ID="EditButton" runat="server" Text="Edit" CommandName="Edit" /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
cs:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridDataItem) |
| { |
| GridDataItem dataItem = (GridDataItem)e.Item; |
| if(dataItem["User"].Text=="NonAdminUser") |
| { |
| ((Button)dataItem["EditCol"].FindControl("DeleteButton")).Visible=false; |
| ((Button)dataItem["DeleteCol"].FindControl("EditButton")).Visible=false; |
| } |
| } |
| } |
Thanks
Princy.
0
Spacewarp
Top achievements
Rank 1
answered on 19 Jan 2009, 04:32 PM
Thank you for the response.
No, we don't have a column bound to the user.
I didn't develop this section, but the guy who did is on vacation for a week. I've written most of the rest of the site, but am having trouble taking his code and making this part work. We're using VB.Net for the back-end.
For the asp.net code, I've got the following.
Basically, I have users who have 3 different levels. If they are a "manager" or admin for the role, then they get the edit and delete buttons. Otherwise, they just get the listing.
No, we don't have a column bound to the user.
I didn't develop this section, but the guy who did is on vacation for a week. I've written most of the rest of the site, but am having trouble taking his code and making this part work. We're using VB.Net for the back-end.
For the asp.net code, I've got the following.
| <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" |
| ShowStatusBar="true" AllowAutomaticDeletes="True" AllowAutomaticUpdates="True" |
| DataSourceID="InviteeDataSource" GridLines="None" Skin="WebBlue" OnItemDataBound="RadGrid1_ItemDataBound" |
| OnItemUpdated="RadGrid1_ItemUpdated" OnItemDeleted="RadGrid1_ItemDeleted" OnDataBound="RadGrid1_DataBound"> |
| <MasterTableView EditMode="PopUp" AutoGenerateColumns="False" DataKeyNames="WSID,UserID" |
| DataSourceID="InviteeDataSource"> |
| <EditFormSettings CaptionFormatString="Edit Study Participant: {0}" CaptionDataField="User_Name" |
| PopUpSettings-Height="250px" PopUpSettings-Width="400px" FormStyle-BackColor="white" /> |
| <Columns> |
| <telerik:GridEditCommandColumn UpdateImageUrl="images/Update.gif" CancelImageUrl="images/Cancel.gif" |
| ButtonType="ImageButton" UniqueName="EditCommandColumn"> |
| </telerik:GridEditCommandColumn> |
| <telerik:GridBoundColumn DataField="WSID" DataType="System.Int32" EmptyDataText="&nbsp;" |
| HeaderText="WSID" SortExpression="WSID" UniqueName="WSID" Display="false" ReadOnly="True"> |
| </telerik:GridBoundColumn> |
| <telerik:GridTemplateColumn DataField="User_Name" HeaderText="Name" SortExpression="User_Name" |
| UniqueName="User_Name"> |
| <ItemTemplate> |
| <asp:Label ID="lblFullName" runat="server" Text='<%# Eval("User_Name") %>' /> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <asp:Label ID="lblFullNameEdit" runat="server" Text='<%# Eval("User_Name") %>' /> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn DataField="Access_Level" HeaderText="Access Level" SortExpression="Access_Level" |
| UniqueName="Access_Level"> |
| <ItemTemplate> |
| <asp:Label ID="lblAccessLevel" runat="server" Text='<%# Eval("Access_Level") %>' /> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <asp:DropDownList ID="ddlAccessLevelEdit" runat="server" CssClass="textbox-cellbox"> |
| <asp:ListItem Value="1" Text="Read Only"></asp:ListItem> |
| <asp:ListItem Value="2" Text="Submitter"></asp:ListItem> |
| <asp:ListItem Value="3" Text="Manager"></asp:ListItem> |
| </asp:DropDownList> |
| <asp:RequiredFieldValidator ID="RequiredFieldValidator3" Display="Dynamic" runat="server" |
| ControlToValidate="ddlAccessLevelEdit" InitialValue="-1" ErrorMessage="*" ToolTip="Select Invitee's Access Level" /> |
| <asp:Label ID="hideAccessLevel" Visible="false" runat="server" Text='<%# Eval("Access_Level") %>' /> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridBoundColumn DataField="CompanySite" EmptyDataText="&nbsp;" HeaderText="Company/Site" |
| SortExpression="CompanySite" UniqueName="CompanySite"> |
| </telerik:GridBoundColumn> |
| <telerik:GridHyperLinkColumn DataNavigateUrlFormatString="mailto:{0}" DataTextField="Email" |
| DataNavigateUrlFields="Email" HeaderText="Email" SortExpression="Email" UniqueName="Email"> |
| </telerik:GridHyperLinkColumn> |
| <telerik:GridTemplateColumn DataField="Last_Accessed" HeaderText="Last Accessed" |
| SortExpression="Last_Accessed" UniqueName="Last_Accessed"> |
| <ItemTemplate> |
| <asp:Label ID="lblLastAccessed" runat="server" Text='<%# Eval("Last_Accessed") %>' /> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <asp:Label ID="lblLastAccessedEdit" runat="server" Text='<%# Eval("Last_Accessed") %>' /> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridBoundColumn DataField="UserID" ReadOnly="True" EmptyDataText="&nbsp;" |
| HeaderText="UserID" SortExpression="UserID" UniqueName="UserID" Display="false"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Level_Num" ReadOnly="True" DataType="System.Int32" |
| EmptyDataText="&nbsp;" HeaderText="Level_Num" SortExpression="Level_Num" |
| UniqueName="Level_Num" Display="false"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="AuthorizedUser" ReadOnly="True" DataType="System.Int32" |
| EmptyDataText="&nbsp;" HeaderText="AuthorizedUser" SortExpression="AuthorizedUser" |
| UniqueName="AuthorizedUser"> |
| </telerik:GridBoundColumn> |
| <telerik:GridTemplateColumn DataField="Represents" HeaderText="Represents" SortExpression="Represents" |
| UniqueName="Represents"> |
| <ItemTemplate> |
| <asp:Label ID="lblRepresents" runat="server" Text='<%# Eval("Represents") %>' /> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <asp:DropDownList ID="ddlAccessRoleEdit" runat="server" CssClass="textbox-cellbox"> |
| </asp:DropDownList> |
| <asp:RequiredFieldValidator ID="RequiredFieldValidator17" Display="Dynamic" runat="server" |
| ControlToValidate="ddlAccessRoleEdit" InitialValue="-1" ErrorMessage="*" ToolTip="Select Invitee's Role" /> |
| <asp:Label ID="hideRepresents" runat="server" Visible="false" Text='<%# Eval("Represents") %>' /> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridButtonColumn ConfirmDialogType="RadWindow" ConfirmText="Delete this participant?" |
| ImageUrl="" ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn1"> |
| <HeaderStyle Width="20px" /> |
| <ItemStyle HorizontalAlign="Center" /> |
| </telerik:GridButtonColumn> |
| </Columns> |
| </MasterTableView> |
| <ClientSettings> |
| <ClientEvents OnPopUpShowing="PopUpShowing" /> |
| <Selecting AllowRowSelect="true" /> |
| </ClientSettings> |
| </telerik:RadGrid><br /> |
| If (TypeOf e.Item Is GridDataItem) Then |
| 'the item is in regular mode |
| 'Dim dataItem As GridDataItem = CType(e.Item, GridDataItem) |
| 'Dim txtEmail As String = CType(dataItem("Access_Level").FindControl("hideEmail"), Label).ToString() |
| 'do something here |
| If UserIsAdmin Then ' Function to check to see if the current user is an admin for this particular record. |
| Dim dataItem As GridDataItem = e.Item |
| Dim lb As New LinkButton |
| lb = dataItem("EditCommandColumn").FindControl("EditCommandColumn") |
| lb.Visible = False |
| lb = dataItem("DeleteColumn1").FindControl("EditButton") |
| lb.Visible = False |
| End If |
Basically, I have users who have 3 different levels. If they are a "manager" or admin for the role, then they get the edit and delete buttons. Otherwise, they just get the listing.
0
Princy
Top achievements
Rank 2
answered on 20 Jan 2009, 06:03 AM
Hi,
I suppose Access_Level field in your database displays the user level. If thats the case then you can set the Access_Level field as the DataKeyName for your grid and try the following code:
aspx:
cs:
Thanks
Princy.
I suppose Access_Level field in your database displays the user level. If thats the case then you can set the Access_Level field as the DataKeyName for your grid and try the following code:
aspx:
| <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" ShowStatusBar="true" AllowAutomaticDeletes="True" AllowAutomaticUpdates="True" DataSourceID="InviteeDataSource" GridLines="None" Skin="WebBlue" OnItemDataBound="RadGrid1_ItemDataBound" OnItemUpdated="RadGrid1_ItemUpdated" OnItemDeleted="RadGrid1_ItemDeleted" OnDataBound="RadGrid1_DataBound"> |
| <MasterTableView EditMode="PopUp" AutoGenerateColumns="False" DataKeyNames="WSID,UserID,Access_Level" DataSourceID="InviteeDataSource"> |
cs:
| Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) |
| If TypeOf e.Item Is GridDataItem Then |
| Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem) |
| If dataItem.GetDataKeyValue("Access_Level").ToString() = "Manager" Then |
| DirectCast(dataItem("EditCommandColumn").Controls(0), ImageButton).Visible = False |
| DirectCast(dataItem("DeleteColumn1").Controls(0), ImageButton).Visible = False |
| End If |
| End If |
| End Sub |
Thanks
Princy.