Link to home
Start Free TrialLog in
Avatar of NP2322
NP2322Flag for United States of America

asked on

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" />
            </DeleteParameters>
       
        </asp:SqlDataSource>

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.
Avatar of daniel_balla
daniel_balla

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

Cheers!
Dani
Avatar of NP2322

ASKER

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

Thanks!
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.

Paul
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.
ASKER CERTIFIED SOLUTION
Avatar of samme
samme
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NP2322

ASKER

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" />
                        <Columns>
                            <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" />
                        </Columns>
                        <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" />
                    </asp:GridView>


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