Vote count:
0
I have a GridView filled with all the data in the Course table. I want to enable deleting and editing only for the courses taught by the user (Professor) who is currently logged in. I keep the professor ID in the Course table and I know how to take the ID of the user who is logged in, but I can't restrict the appearance of the Edit and Delete links.
I tried to work with the OnRowDataBound event, but all I managed to do is not to display this column at all, which leaded to a terrible look of the page.
Here's what I tried:
protected void coursesGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState ==
DataControlRowState.Normal)
{
e.Row.Controls[0].Visible = false;
}
}
This is the code for the drop down list:
<asp:GridView runat="server" ID="coursesGrid"
ItemType="CoursesManager.Models.Course"
DataKeyNames="CourseID"
SelectMethod="coursesGrid_GetData"
UpdateMethod="coursesGrid_UpdateItem"
DeleteMethod="coursesGrid_DeleteItem"
AutoGenerateColumns="False"
OnRowDataBound="coursesGrid_RowDataBound">
<Columns>
<asp:CommandField ShowEditButton='True' ShowDeleteButton='True'/>
<asp:DynamicField DataField="Topic" />
</Columns>
</asp:GridView>
asked 31 secs ago
How to enable editing and deleting only for some rows (dynamically) in a ASP.NET GridView?
Aucun commentaire:
Enregistrer un commentaire