not understanding updating/deleting with gridview

M

Mike P

When you specify updateparameters or deleteparameters for your gridview,
I was under the impression that whether or not you write some code in
the rowcommand event to deal with this, the update or delete happens
anyway. For example, I have a gridview like this :

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

SelectCommand="GetOppsTypeList" SelectCommandType="StoredProcedure"

UpdateCommand="UpdateOpportunity" UpdateCommandType="StoredProcedure"

DeleteCommand="DeleteOpportunity" DeleteCommandType="StoredProcedure">

<SelectParameters>

<asp:QueryStringParameter Name="CompanyKey"
QueryStringField="CompanyKey" Type="Int64" />

<asp:QueryStringParameter Name="OpportunityName"
QueryStringField="OpportunityName" Type="Int32" />

<asp:ControlParameter Name="Status" ControlID="ddlStatus"
PropertyName="SelectedValue" DefaultValue="All" />

</SelectParameters>

<UpdateParameters>

<asp:parameter Name="OpportunityTypeID" Type="Int32" />

<asp:parameter Name="DivisionID" Type="Int32" />

<asp:parameter Name="XeroxMachineType" Type="String" />

<asp:parameter Name="Model" Type="String" />

<asp:parameter Name="ProbabilityID" Type="Int32" />

<asp:parameter Name="MonetaryValue" Type="Double" />

<asp:parameter Name="OpportunityID" Type="Int32" />

</UpdateParameters>

<DeleteParameters>

<asp:parameter Name="OpportunityID" Type="Int32" />

</DeleteParameters>

And here are the relevant columns :

<asp:ButtonField ButtonType="Image" ImageUrl="~/Images/btnAddLog.jpg"
CommandName="AddLog" />

<asp:ButtonField ButtonType="Image" ImageUrl="~/Images/btnDetails.jpg"
CommandName="OpportunityDetails" />


<asp:CommandField ShowEditButton="True" ButtonType="Image"
EditImageUrl="~/Images/btnEdit.jpg"

CancelImageUrl="~/Images/btnCancel.jpg"
UpdateImageUrl="~/Images/btnUpdate.jpg"/>


<asp:TemplateField>

<ItemTemplate>

<asp:ImageButton ID="DeleteButton"

ImageUrl="~/Images/btnDelete.jpg"

CommandName="Delete" runat="server"

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

OnClientClick="return confirm('Are you sure you want to delete this
opportunity?');">

</asp:ImageButton>

</ItemTemplate>

</asp:TemplateField>



Now when I want to 'Add Log', a command I have created myself, I need to
do so here :

protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)

{

if (e.CommandName == "AddLog")

{

}

But for a delete, if I have delete parameters specified, the delete
takes place without the need for any code in the rowcommand event. But
why is this not the case for the update? I was trying to validate
deletions in the rowcommand event, but found that the delete had already
taken place before it reached this event, whilst I was able to validate
the update event with custom code in the rowcommand event, as the update
did not happen before the rowcommand event was reached.

Why does it happen like this?
 

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

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top