Dennis Hertzler
Dennis Hertzler

Reputation: 90

How to Make A SQL Data Source Delete Statement Delete Selected Item

I am trying to delete the selected item on a grid view from a sql server database. I have my DataKeyNames set and a sql data source with the grid view pointing to it. I have a delete command:

DeleteCommand="DELETE FROM cartsigns WHERE SignName = @SignName" 

And A select command:

SelectCommand="SELECT * FROM cartsigns WHERE ((ipaddress = @ipaddress) AND (ipaddress = @ipaddress2))" 

I then have my delete paramerter:

    <DeleteParameters>
         <asp:ControlParameter 
            ControlID="GridView1" 
            Name="SignName" 
            PropertyName="SelectedDataKey" />
    </DeleteParameters>

But when I select a item and push the delete button it does not delete. Thanks for your help.

p.s. The purpose for this is a shopping cart and I want to be able to delete items in my cart.

Please Please Help

Upvotes: 0

Views: 152

Answers (1)

Dennis Hertzler
Dennis Hertzler

Reputation: 90

I figured out my problem! I needed to change my property name on my delete paramerters to SelectedValue.

I also had forgot to set my key on my database. And I accidently changed my sort expressions, but after I got those fixed it started working.

Upvotes: 1

Related Questions