From your description, I understand that you're developing an ASP.NET 2.0
web application. In one page, you're using DataGrid control(or GridView?)
and the grid has one edit command column. However, you're wondering how to
make the edit/update function only available to certain grant users,
correct?
Yes, that is correct. I'd prefer to hide the column; currrently I'm disabling the entire grid like this:
dgAircraft.Enabled = Session("user_type") <> "VIEWONLY"
Two other items which will certainly have an impact: I'm using MasterPages, and the Datagrids which need to be disabled
are on Web User Controls.
1. We can get the certain EditCommand column from the GridView or DataGrid
control's "Columns" collection (through index) and then set its visble to
true/false according to the current visit user's identity.
2. If you do not want to hide the entire column, we can consider use the
DataGrid's ItemDataBound or GridView's RowDataBound event, in these events,
we can get certain inner control's reference from the column/cell and then
set their enabled property. BTW, it is recommend that we use template
column/template field for such scenario so that it'll be easier to
determine the control's ID so as to use FindControl to locate them.
Also, if convenient, you can post the detailed page template and code
snippet here so that we can help have a look to see whether there is
anything incorrect.
Here's a sample from one of the UserControls ascx pages. Unfortunately I deleted the code where I was attempting to
locate the column, so I have nothing to post regarding that. I was trying to run the code in the Page_LoadComplete
event.
<asp
ataGrid id=<%@ Reference Control="~/WebControls/commoncontrol.ascx" %>
<%@ Register TagPrefix="igsch" Namespace="Infragistics.WebUI.WebSchedule" Assembly="Infragistics.WebUI.WebDateChooser.v5.3, Version=5.3.20053.50, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" %>
<%@ Control Language="vb" AutoEventWireup="false" Inherits="webPilotLogBook.Certificates" CodeFile="Certificates.ascx.vb" CodeFileBaseClass="webPilotLogBook.CommonControl" %>
<asp
ataGrid id="dgCertificates" runat="server" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
BackColor="White" CellPadding="3" GridLines="Vertical" Font-Size="8pt" Font-Names="Verdana"
AutoGenerateColumns="False" ShowFooter="True" AllowPaging="True" Width="600px">
<FooterStyle ForeColor="Black" BackColor="#CCCCCC" />
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C" />
<AlternatingItemStyle BackColor="Gainsboro" />
<ItemStyle ForeColor="Black" BackColor="#EEEEEE" />
<HeaderStyle CssClass="flightLogField" />
<Columns>
<asp:BoundColumn Visible="False" DataField="lngCertificateID" SortExpression="lngCertificateID"
HeaderText="lngCertificateID"></asp:BoundColumn>
<asp:BoundColumn DataField="strGrade" SortExpression="strGrade" HeaderText="Grade"></asp:BoundColumn>
<asp:BoundColumn DataField="strNumber" SortExpression="strNumber" HeaderText="Number"></asp:BoundColumn>
<asp:BoundColumn DataField="dteDateIssued" SortExpression="dteDateIssued" HeaderText="Date Issued"
DataFormatString="{0:d}">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="strRemarks" SortExpression="strRemarks" HeaderText="Remarks"></asp:BoundColumn>
<asp:EditCommandColumn CancelText="Cancel" EditText="Edit" UpdateText="Update"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="DELETE">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<FooterStyle HorizontalAlign="Right"></FooterStyle>
</asp:ButtonColumn>
</Columns>