I have a Gridview that shows a list of Contacts via a sqlDataSource.
Included is an Item Template for Deleting a record - a LinkButton - with OnClientClick set to use some JavaScript: "return confirm('Are you sure you want to delete this user?');" This give the user a little pop up with a Yes or Cancel option.
When the user is deleted from the Contact table, I also need to delete the same user in the AspNet Membership tables using Membership.DeleteUser(UserName, true) statement.
The Contact.IntranetUserName column and UserName of the Membership tables contain the same data values, so that makes things convenient.
Not knowing what event to use, I started with using the Gridview's OnRowCommand - but can't figure out how to grab the value of the "IntranetUserName" column of the row that's being deleted (by the Item Template in Contact Table) and pass it to the Membership.DeleteUser statement.
Any C# ideas on this would be much apprecitated. Perhaps I should be using GridView's OnRowDeleted or OnRowDeleting instead? Or perhaps the LinkButtons OnCommand?
GridView and SqlDataSource here:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ContactID"
DataSourceID="SqlDataSource2" Width="738px" OnRowCommand="deleteFromAspnetProvider" >
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return confirm('Are you sure you want to delete this user?');"
CommandName="Delete" Text="Delete User"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="IntranetUserName" HeaderText="IntranetUserName" SortExpression="IntranetUserName" Visible="false" />
<asp:BoundField DataField="FirstName" HeaderText="First Name"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="Last Name"
SortExpression="LastName" />
<asp:BoundField DataField="CompanyName" HeaderText="Company"
SortExpression="CompanyName" />
<asp:BoundField DataField="EmailAddress" HeaderText="Email Address"
SortExpression="EmailAddress" />
<asp:BoundField DataField="UserLevelType" HeaderText="UserLevelType"
SortExpression="UserLevelType" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:DataConnect %>"
SelectCommand="SELECT * FROM [Contact] WHERE ([CompanyName] = @CompanyName)"
DeleteCommand="DELETE FROM [Contact] WHERE [ContactID] = @ContactID"
InsertCommand="INSERT INTO [Contact] ([UserId], [UserSID], [LocationID], [IntranetUserName], [FirstName], [LastName], [CompanyName], [EmailAddress], [ContactPhone], [ContactPhoneExt], [ContactFAX], [DateUpdated], [ActiveMember], [UserLevelType]) VALUES (@UserId, @UserSID, @LocationID, @IntranetUserName, @FirstName, @LastName, @CompanyName, @EmailAddress, @ContactPhone, @ContactPhoneExt, @ContactFAX, @DateUpdated, @ActiveMember, @UserLevelType)"
UpdateCommand="UPDATE [Contact] SET [UserId] = @UserId, [UserSID] = @UserSID, [LocationID] = @LocationID, [IntranetUserName] = @IntranetUserName, [FirstName] = @FirstName, [LastName] = @LastName, [CompanyName] = @CompanyName, [EmailAddress] = @EmailAddress, [ContactPhone] = @ContactPhone, [ContactPhoneExt] = @ContactPhoneExt, [ContactFAX] = @ContactFAX, [DateUpdated] = @DateUpdated, [ActiveMember] = @ActiveMember, [UserLevelType] = @UserLevelType WHERE [ContactID] = @ContactID">
<SelectParameters>
<asp:ControlParameter ControlID="memberCompanyNameLabel" Name="CompanyName"
PropertyName="Text" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ContactID" Type="Int32" />
<asp:Parameter Name="IntranetUserName" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="UserId" Type="Object" />
<asp:Parameter Name="UserSID" Type="Int32" />
<asp:Parameter Name="LocationID" Type="Int32" />
<asp:Parameter Name="IntranetUserName" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="CompanyName" Type="String" />
<asp:Parameter Name="EmailAddress" Type="String" />
<asp:Parameter Name="ContactPhone" Type="String" />
<asp:Parameter Name="ContactPhoneExt" Type="String" />
<asp:Parameter Name="ContactFAX" Type="String" />
<asp:Parameter Name="DateUpdated" Type="DateTime" />
<asp:Parameter Name="ActiveMember" Type="Boolean" />
<asp:Parameter Name="UserLevelType" Type="Int32" />
<asp:Parameter Name="ContactID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="UserId" Type="Object" />
<asp:Parameter Name="UserSID" Type="Int32" />
<asp:Parameter Name="LocationID" Type="Int32" />
<asp:Parameter Name="IntranetUserName" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="CompanyName" Type="String" />
<asp:Parameter Name="EmailAddress" Type="String" />
<asp:Parameter Name="ContactPhone" Type="String" />
<asp:Parameter Name="ContactPhoneExt" Type="String" />
<asp:Parameter Name="ContactFAX" Type="String" />
<asp:Parameter Name="DateUpdated" Type="DateTime" />
<asp:Parameter Name="ActiveMember" Type="Boolean" />
<asp:Parameter Name="UserLevelType" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>