title: How to use a LinkButton inside gridview to delete selected username in the code-behind file?
body: <p>I have a "UserDetail" table in my "JobPost.mdf".
  I have a "Gridview1" showing the column from "UserDetail" table,which has a primary key "UserName".
  This "UserName" is originally saved using Membership class function.
  Now I add a "Delete" linkbutton to the GridView1. This "Delete" is not autogenerate button,I dragged inside the column itemtemplate from ToolBox.
  The GridView1's columns now become "Delete_LinkButton"+"UserName"(within the UserDetail table)+"City"(within the UserDetail table)+"IsAdmin"(within the UserDetail table)</p>
  
  <p>What I need is that by clicking this "delete_linkButton",it will ONLY delete the entire User Entity on the same row (link by the corresponding "UserName") from the "UserDetail" table,as well as delete all information from the AspNetDB.mdf (User,Membership,UserInRole,etc).</p>
  
  <p>I would like to fireup a user confirm,but not mandatory. At least I am trying to make it functional in the correct way.</p>
  
  <pre><code>for example:
  
  Command     UserName    City           IsAdmin
  delete           ken       Los Angles          TRUE
  delete           jim        Toronto        FALSE
  </code></pre>
  
  <p>When I click "delete" on the first row, I need all the record about "ken" inside the "UserDetail" table to be removed. Meanwhile, all the record about "ken" in the AspNetDB.mdf will be gone, including UserinRole table.</p>
  
  <p>I am new to asp.net, so I don't know how to pass the commandargument of the "Delete_LinkButton" to the code-behind file LinkButton1_Click(object sender, EventArgs e), because I need one extra parameter "UserName".</p>
  
  <p>My partial code is listed below:</p>
  
  <pre><code>&lt;asp:TemplateField&gt;
                   &lt;ItemTemplate&gt;
                       &lt;asp:LinkButton ID="Delete_LinkButton" runat="server" onclick="LinkButton1_Click1" CommandArgument='&lt;%# Eval("UserName","{0}") %&gt;'&gt;LinkButton&lt;/asp:LinkButton&gt;
                   &lt;/ItemTemplate&gt;
               &lt;/asp:TemplateField&gt;
  
  
  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();
  
  
       }
  </code></pre>
  
  <p>Please do help!</p>