SqlDataSource DeleteParameters

M

Mike P

I'm a little confused as to how the SqlDataSource works with its
DeleteParameters. I have a GridView hooked up to my SqlDataSource.
Here is my templatefield with my Delete button :

<asp:TemplateField HeaderText="Select">

<ItemTemplate>

<asp:LinkButton ID="DeleteButton"

CommandArgument='<%# Eval("ForecastKey") %>'

CommandName="Delete" runat="server">

Delete</asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>



And here is my SqlDataSource :

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:XeroxConnectionString %>"

SelectCommand="ViewForecast" SelectCommandType="StoredProcedure"

DeleteCommand="DeleteForecast" DeleteCommandType="StoredProcedure">



</asp:SqlDataSource>

My stored procedure requires 1 parameter (ForecastKey) to be passed to
it, but I can get away with not specifying DeleteParameters in my
SqlDataSource and it still deletes the record. Any ideas why it does
this, and whether this method of not specifying parameters is a
recommended way to do this?
 
B

Brock Allen

The values defined in DataKeyNames of your DataBoundControl are always passed
as arguments to the various commands (update, insert, delete), so no declarative
parameter is required (*despite* the silly designer/wizard putting one in).
Same goes for all columns that are returns from the SelectCommand -- IOW,
those are always passed to your various update commands as well.

-Brock
http://staff.develop.com/ballen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top