XyBoy Posted December 5, 2008 Posted December 5, 2008 Hi, I have some little experience with asp.net but I'm juste beginning with VS2008 and Linq. I'm 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 : <asp:GridView ID="GridUsers" runat="server" DataKeyNames="UserID" onrowdeleting="GridUsers_RowDeleting" > (with a "Delete" command field). And in the code behind I have the following databinding : 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 can't find how to retrieve the UserID for the deleted row : 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(); } I've looked everywhere on the web but I can't 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 I'm engaged in a wrong way. Thank you. Olivier. Quote
IxiRancid Posted January 17, 2009 Posted January 17, 2009 When you say: e.RowItem = 0 that is the row index which user has clicked in. So you can use this like this: GridUsers.DataKeys(e.RowItem).Value.ToString() '(sorry it's in vb.net) [/Code] Let me know if this works. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.