Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1731
  • Last Modified:

DeleteCommand in GridView Not Responding

I have a gridview on me .aspx page and i'm trying to get the deletecommand to work. When i click it, the page gets refreshed but the item i clicked to delete remains both on the page and in the database. Below is an example of my source. I had it working at one point and then I changed some things around and it stopped responding.

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            SelectCommand="SELECT [UserName], [Email], [PermissionName], [LastLoginDate] FROM [vw_aspnet_UserInfo]"
            Deletecommand="DELETE FROM aspnet_Users WHERE UserName = @original_UserName">
            <DeleteParameters >
                <asp:Parameter Name="original_UserName" Type="String" />

Does anyone see where i'm going wrong or what i could be doing differently? I'm new to ASP.Net and so i'm still trying to get a hold of things.
1 Solution
Hi NP2322,
can you post your gridview source as well?

NP2322Author Commented:
just left work, i'll get it on here on Monday.

Check the definition of your SqlDataSource.

If you're not using optimistic  concurrency, but have an updatable key-column then In the definition for your SqlDataSource you need to make sure that you have "OldValuesParameterFormatString="original_" defined.

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

rhen is probably right. the reason you see the page refresh is because the datasource is running the sql, but there's nothing telling it what that parameter is, so it doesn't delete anything.
You can also try adding  ", UserName" in the datakeynames property of the gridview
NP2322Author Commented:
Gridview source:

                    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                        CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <asp:CommandField ShowDeleteButton="True" />
                            <asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
                            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                            <asp:BoundField DataField="PermissionName" HeaderText="PermissionName" SortExpression="PermissionName" />
                            <asp:BoundField DataField="LastLoginDate" HeaderText="LastLoginDate" SortExpression="LastLoginDate" />
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        <EditRowStyle BackColor="#999999" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

I tried adding "OldValuesParameterFormatString="original_", didn't seem to work. Any other ideas?

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now