I probably should have done this the first time. Below is my
GridView. The example you provided above produces the following
Error:
Specified argument was out of the range of valid values.
Parameter name: index
<asp:GridView ID="NotesGridView" runat="server" AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="fnID"
DataSourceID="GridViewSqlDataSource"
PageSize="6"
onselectedindexchanged="NotesGridView_SelectedIndexChanged"
onrowdatabound="NotesGridView_RowDataBound">
<Columns>
<asp:CommandField ShowDeleteButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="fnID"
HeaderText="fnID" InsertVisible="False"
ReadOnly="True" SortExpression="fnID"
Visible="False" />
<asp:BoundField DataField="fID"
HeaderText="fID" SortExpression="fID"
Visible="False" />
<asp:BoundField DataField="Type"
HeaderText="Type" SortExpression="Type" />
<asp:BoundField DataField="Note"
HeaderText="Note" SortExpression="Note" >
<ControlStyle Height="50px" Width="300px" /</asp:BoundField>
<asp:CheckBoxField DataField="Display"
HeaderText="Display"
SortExpression="Display" />
</Columns>
</asp:GridView>
Thanks for the quick response. Can you elaborate on the Code
Behind? There are actually 3 roles that get to delete. If you can
provide an example it would help tremendously.
I was thinking about something along these lines:
void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
((LinkButton)e.Row.Cells[1].Controls[1]).Enabled =
User.IsInRole(...) || User.IsInRole(...) || User.IsInRole(...);
}
}
Of course, instead of Cells[1].Controls[1] you will need to insert the
correct cell and control index to match the design of your grid. If you
don't know the numbers, or you plan to modify the design frequently, you can
use FindControl(name) instead.