I have a table called "UserDetail" in my "JobPost.mdf". I have a "Gridview1" showing a column from the "UserDetail" table that has the primary key "UserName". This "UserName" is initially stored using the function of the Membership class. Now I am adding a Delete link to GridView1. This โDeleteโ is not a self-generating button, and I dragged it into the itemtemplate element of the column from the ToolBox. Graphs GridView1 now become "Delete_LinkButton" + "UserName" (in the UserDetail table) + "City" (in the UserDetail table) + "IsAdmin" (in the UserDetail table)
I need to click this "delete_linkButton", it ONLY removes the entire user entity in the same row (the link corresponding to "UserName") from the "UserDetail" table, and also removes all information from AspNetDB.mdf (User, Membership, UserInRole, etc.) .d.).
I would like the user to be able to confirm, but not necessarily. At least I'm trying to make it functional correctly.
for example: Command UserName City IsAdmin delete ken Los Angles TRUE delete jim Toronto FALSE
When I press delete in the first row, I need the entire ken entry inside the UserDetail table to be deleted. Meanwhile, all entries about "ken" in AspNetDB.mdf will disappear, including the UserinRole table.
I am new to asp.net, so I donโt know how to pass the "Delete_LinkButton" command parameter to the LinkButton1_Click code file (object sender, EventArgs e), because I need one additional parameter "UserName" ".
My partial code is below:
<asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="Delete_LinkButton" runat="server" onclick="LinkButton1_Click1" CommandArgument='<%# Eval("UserName","{0}") %>'>LinkButton</asp:LinkButton> </ItemTemplate> </asp:TemplateField> protected void Delete_LinkButton_Click(object sender, EventArgs e) { ((LinkButton) GridView1.FindControl("Delete_LinkButton")).Attributes.Add("onclick", "'return confirm('Are you sure you want to delete {0} '" + UserName); Membership.DeleteUser(UserName); JobPostDataContext db = new JobPostDataContext(); var query = from u in db.UserDetails where u.UserName == UserName select u; for (var Item in query) { db.UserDetails.DeleteOnSubmit(Item); } db.SubmitChanges(); }
Please, help!
source share