Hi,
I have some little experience with asp.net but Im juste beginning with VS2008 and Linq. Im trying to do a little control to manage a "User group" (allowing to add and remove users from the group).
So I defined a GridView like this :
(with a "Delete" command field).
And in the code behind I have the following databinding :
But in the "GridUsers_RowDeleting" method, I cant find how to retrieve the UserID for the deleted row :
Ive looked everywhere on the web but I cant find the right way to do it.
I found this topic : http://forums.asp.net/t/1107245.aspx but the answer given by "adefwebserver" does not work (e.RowItem is not the Key : when I have on single row in my table, with UserID=2, e.RowItem = 0 !).
Please tell me if Im engaged in a wrong way.
Thank you.
Olivier.
I have some little experience with asp.net but Im juste beginning with VS2008 and Linq. Im trying to do a little control to manage a "User group" (allowing to add and remove users from the group).
So I defined a GridView like this :
Code:
<asp:GridView ID="GridUsers" runat="server" DataKeyNames="UserID"
onrowdeleting="GridUsers_RowDeleting" >
And in the code behind I have the following databinding :
Code:
GridUsers.DataSource = from u in DC.OJC_UserGroups_Users
where u.UserGroupID == this.UserGroupID
select new { u.UserID, u.User.FirstName, u.User.LastName };
GridUsers.DataBind();
But in the "GridUsers_RowDeleting" method, I cant find how to retrieve the UserID for the deleted row :
Code:
protected void GridUsers_RowDeleting(object sender, GridViewDeleteEventArgs e) {
int userID = (int)e.Keys[0];
Group.Users.Remove(Group.Users.First<OJC_UserGroups_Users>(x => x.UserID == userID));
DC.SubmitChanges();
}
Ive looked everywhere on the web but I cant find the right way to do it.
I found this topic : http://forums.asp.net/t/1107245.aspx but the answer given by "adefwebserver" does not work (e.RowItem is not the Key : when I have on single row in my table, with UserID=2, e.RowItem = 0 !).
Please tell me if Im engaged in a wrong way.
Thank you.
Olivier.