DeleteCommand in GridView Not Responding

Posted on 2006-10-27
Last Modified: 2008-01-09
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.
Question by:NP2322

Expert Comment

ID: 17822738
Hi NP2322,
can you post your gridview source as well?


Author Comment

ID: 17822939
just left work, i'll get it on here on Monday.


Expert Comment

ID: 17822972
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.

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

LVL 12

Expert Comment

ID: 17823243
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.

Accepted Solution

samme earned 250 total points
ID: 17826385
You can also try adding  ", UserName" in the datakeynames property of the gridview

Author Comment

ID: 17833858
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now