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>
<asparameter Name="OpportunityTypeID" Type="Int32" />
<asparameter Name="DivisionID" Type="Int32" />
<asparameter Name="XeroxMachineType" Type="String" />
<asparameter Name="Model" Type="String" />
<asparameter Name="ProbabilityID" Type="Int32" />
<asparameter Name="MonetaryValue" Type="Double" />
<asparameter Name="OpportunityID" Type="Int32" />
</UpdateParameters>
<DeleteParameters>
<asparameter 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?
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>
<asparameter Name="OpportunityTypeID" Type="Int32" />
<asparameter Name="DivisionID" Type="Int32" />
<asparameter Name="XeroxMachineType" Type="String" />
<asparameter Name="Model" Type="String" />
<asparameter Name="ProbabilityID" Type="Int32" />
<asparameter Name="MonetaryValue" Type="Double" />
<asparameter Name="OpportunityID" Type="Int32" />
</UpdateParameters>
<DeleteParameters>
<asparameter 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?