I need to hide the RevToDate
column in the DataGrid
for any user who is not admin. How do I hide only this column?
<asp:DataGrid runat="server" CssClass="tblResults" OnItemDataBound="dgList_ItemCreated" AllowSorting="true" OnSortCommand="dgCustomer_Sort" ID="dgCustomers" DataKeyField="ID" AutoGenerateColumns="false">
<HeaderStyle CssClass="tblResultsHeader" />
<AlternatingItemStyle BackColor="#EEEEEE" />
<Columns>
<asp:HyperLinkColumn ItemStyle-CssClass="loading" DataNavigateUrlFormatString="Customer.aspx?CustID={0}" DataNavigateUrlField="ID" DataTextField="AccountCode" HeaderText="A/C Code" SortExpression="AccountCode"></asp:HyperLinkColumn>
<asp:BoundColumn DataField="CurrencyDesc" HeaderText="Currency" SortExpression="CurrencyDesc"></asp:BoundColumn>
<asp:BoundColumn DataField="RevToDate" HeaderText="Rev To Date (Net)" SortExpression="RevToDate"></asp:BoundColumn>
<asp:BoundColumn DataField="CreditLimitAmount" HeaderText="Credit Limit" SortExpression="CreditLimitAmount"></asp:BoundColumn>
<asp:BoundColumn DataField="DiscountReviewDate" HeaderText="Discount Review Date" SortExpression="DiscountReviewDate" Visible="false"></asp:BoundColumn>
</Columns>
</asp:DataGrid
I'm using this code to hide certain items:
if (!CurrentUser.IsInRole("Admin"))
{
btnDelete.Visible = false;
btnUpload2.Visible = false;
}
But I am not sure how to hide the column. I can't set Visible to false in the CSS because it will hide the column from all users.
Example of Show or Hide Column in React Grid ComponentClick column name from the toolbar to toggle visibility.
By opening the column menu and clicking the Hide menu item. By clicking the Columns menu and toggling the columns to show or hide.
The DataGridView control provides a customizable table for displaying data. The DataGridView class allows customization of cells, rows, columns, and borders through the use of properties such as DefaultCellStyle, ColumnHeadersDefaultCellStyle, CellBorderStyle, and GridColor.
You can do like this.
if (!CurrentUser.IsInRole("Admin"))
{
this.dgCustomers.Columns[2].Visible = false;
btnDelete.Visible = false;
btnUpload2.Visible = false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With