0

I made a quick gridview, bound it to a datasource, put in a select statement it works.

I then went into the datasource, and to the delete tab, and put some delete code in, that ends with where blahUID = @blahUID

I checked the enable deleting checkbox, which added a Delete textlink on each line of the gridview.

However when I press it, it errors because @blahUID is not defined - how can I define it?

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="...snipped..." 


SelectCommand="SELECT [CategoryUID], [WordUID], [CategoryName], [Colour] FROM [Category] WHERE ([WordUID] = @WordUID);" 
DeleteCommand="delete from [Category] where CategoryUID = @CategoryUID">
<SelectParameters>
    <asp:ControlParameter ControlID="lstWords" Name="WordUID" 
        PropertyName="SelectedValue" />
</SelectParameters>
<DeleteParameters>
    <asp:Parameter Name="CategoryUID" />
</DeleteParameters>

1 Answer 1

2

Fixed by putting DataKeyNames="CategoryUID" in the gridview parameters.

Sign up to request clarification or add additional context in comments.

1 Comment

Very common problem in the world of GridView's. You must ensure your DataKeyNames are specified. It also works for multiple keys which is handy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.