troubleshooting Question

Used RowCommand - now my standard 'edit' doesn't work!

Avatar of RobertNZana
RobertNZanaFlag for United States of America asked on
.NET ProgrammingASP.NETVisual Basic.NET
4 Comments1 Solution897 ViewsLast Modified:
I am using a databound gridview control.  I have a standard 'edit' button (with save/cancel.)  I wrote no code for this.  It worked great!

Then I added a template field for a 'delete' linkbutton which does some CUSTOM events in addition to deleting.

I use the RowCommand event of the gridview in order to run the custom 'delete' code.  But now my 'edit' button (no code) doesn't work.  Any reason why?
Protected Sub gvSubusers_RowCommand(ByVal sender As Object, ByVal e As 
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles 
gvSubusers.RowCommand
        If e.CommandName = "DeleteSubUser" Then
            Dim u As New MyCompany.BusinessLogicLayer.Users.Users
            Try
                Dim lb As LinkButton = CType(e.CommandSource, LinkButton)
                Dim row As GridViewRow = CType(lb.NamingContainer, 
GridViewRow)
                Dim id As Integer = 
CInt(gvSubusers.DataKeys(row.RowIndex).Values(0))
 
                u.DeleteSubuser(id)    
                Page.DataBind()
            Catch ex As Exception
                lblStatus.Text = ex.ToString
                lblStatus.ForeColor = Drawing.Color.Red
            End Try
        End If
    End Sub
 
'******* HERES THE GRIDVIEW ***********
 
                <asp:GridView ID="gvSubusers" runat="server" CssClass="aspnet_gridview_padleft" AllowPaging="True"
                    AllowSorting="True" AutoGenerateColumns="False" DataSourceID="odsSubUsers" 
                    SkinID="Style2" DataKeyNames="PermissionId">
                    <Columns>
                        <asp:TemplateField HeaderText="Username">
                            <ItemTemplate>
                                <asp:Label ID="lblUsername2" runat="server" Text='<%# Bind("UserName") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:Label ID="lblUsername" runat="server" Text='<%# Bind("UserName") %>'></asp:Label>
                                <asp:Label ID="lblMyCompanyUserId" runat="server" Visible="false" Text='<%# bind("MyCompanyUserId") %>'></asp:Label>
                                <asp:Label ID="lblPermissionId" runat="server" Visible="false" Text='<%# bind("PermissionId") %>'></asp:Label>
                            </EditItemTemplate>
                            <HeaderStyle Width="100px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="First Name">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtFirstName" runat="server" Text='<%# bind("FirstName") %>' Width="90px"></asp:TextBox>
                            </EditItemTemplate>
                            <HeaderStyle Width="100px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Last Name">
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtLastName" runat="server" Text='<%# bind("LastName") %>' Width="90px"></asp:TextBox>
                            </EditItemTemplate>
                            <HeaderStyle Width="100px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Email">
                            <ItemTemplate>
                                <asp:Label ID="Label3" runat="server" Text='<%# Bind("Email") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtEmail" runat="server" Text='<%# bind("Email") %>' Width="110px"></asp:TextBox>
                            </EditItemTemplate>
                            <HeaderStyle Width="110px" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Edit">
                            <ItemTemplate>
                                <asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("AllowEditProjects") %>'
                                    Enabled="false" />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:CheckBox ID="ckEdit" runat="server" Checked='<%# Bind("AllowEditProjects") %>' />
                                <asp:Label ID="lblPermissionId" runat="server" Text='<%# bind("PermissionId") %>'
                                    Visible="False"></asp:Label>
                            </EditItemTemplate>
                        </asp:TemplateField>                                                         
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="btnDelete" runat="server" CommandName="DeleteSubUser" OnClientClick="return confirm('Are you sure you want to PERMANENTLY DELETE this SubUser?');"
                                    Text="Delete"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <EmptyDataTemplate>
                        No sub-users yet.
                    </EmptyDataTemplate>
                    <EditRowStyle CssClass="" />
                </asp:GridView>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros