I currently have a Gridview which uses a ButtonField of type image and this works.
However I want to be able to use the ConfirmButtonExtender that is part of the AjaxControlToolkit which cannot operate on a Buttonfield so I decided to place an ImageButton inside a TemplateField however whenever I click the button I recieve an Invalid postback or callback argument error.
Any advice/suggestions would be greatly appreciated. Thank you.
New template field
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ibtnDelete" ImageUrl="~/Images/cross.png" CommandArgument='<% Eval("soid") %>' CommandName="deleteSO" AlternateText="Delete" OnClick="ibtnDelete_Click" ToolTip="Delete the selected standing order" runat="server" />
</ItemTemplate>
</asp:TemplateField>
Existing GridView
<asp:GridView ID="gvStandingOrders" runat="server" DataKeyNames="soid" OnRowCommand="gvStandingOrders_RowCommand">
<Columns>
<asp:ButtonField ButtonType="Image" CommandName="editSO" ImageUrl="~/Images/page_white_paintbrush.png" Text="Edit" />
<asp:ButtonField ButtonType="Image" CommandName="deleteSO" ImageUrl="~/Images/cross.png" Text="Delete" />
<asp:BoundField DataField="Prefix" HeaderText="Prefix" />
<asp:BoundField DataField="PhoneNumber" HeaderText="Phone Number" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:BoundField DataField="Amount" DataFormatString="{0:C}" HeaderText="Customer Charge" />
<asp:BoundField DataField="SOCost" DataFormatString="{0:C}" HeaderText="Bureau Buy Price" />
<asp:BoundField DataField="UnitPrice" DataFormatString="{0:C}" HeaderText="TMS Buy Price" />
<asp:BoundField DataField="Frequency" HeaderText="Frequency" />
<asp:BoundField DataField="StartDate" DataFormatString="{0:dd/MM/yyyy}" HeaderText="Start Date" />
<asp:BoundField DataField="LastInvoiceDate" DataFormatString="{0:dd/MM/yyyy}" HeaderText="Last Invoice Date" />
<asp:BoundField DataField="NextInvoiceDate" DataFormatString="{0:dd/MM/yyyy}" HeaderText="Next Invoice Date" />
<asp:BoundField DataField="EndDate" DataFormatString="{0:dd/MM/yyyy}" HeaderText="End Date" />
<asp:BoundField DataField="soid" HeaderText="SO ID" />
</Columns>
</asp:GridView>
Code behind
protected void gvStandingOrders_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("editSO"))
{
Session["SOID"] = Convert.ToInt32(gvStandingOrders.DataKeys[Convert.ToInt32(e.CommandArgument)].Value);
Response.Redirect("/Main/ClientMaintenance/StandingOrders/EditStandingOrder.aspx", true);
}
else if (e.CommandName.Equals("deleteSO"))
{
int soid = Convert.ToInt32(gvStandingOrders.DataKeys[Convert.ToInt32(e.CommandArgument)].Value);
// Header
int provisionID = Provisioning.GenerateHeader("SO", "provisioning_standingorder");
// Create Details
GlobFunctions.UpdateStoredProc("InsertStandingOrderHeader", GlobVar.ObjConnClick, new SqlParameter[]
{
new SqlParameter("@ProvisionID", provisionID),
new SqlParameter("@Client_Action", "D"),
new SqlParameter("@SOID", soid)
});
// Audit
GlobFunctions.AddToAudit(String.Format("Removing standing order : {0}", soid), Session["CustomerCode"].ToString());
}
}
protected void ibtnDelete_Click(object sender, ImageClickEventArgs e)
{
//select the row
ImageButton imageButton = (ImageButton)sender;
TableCell tableCell = (TableCell)imageButton.Parent;
GridViewRow row = (GridViewRow)tableCell.Parent;
int soid = Convert.ToInt32(gvStandingOrders.DataKeys[Convert.ToInt32(row.RowIndex)].Value);
// Header
int provisionID = Provisioning.GenerateHeader("SO", "provisioning_standingorder");
// Create Details
GlobFunctions.UpdateStoredProc("CLICK10_InsertStandingOrderHeader", GlobVar.ObjConnClick, new SqlParameter[]
{
new SqlParameter("@ProvisionID", provisionID),
new SqlParameter("@Client_Action", "D"),
new SqlParameter("@SOID", soid)
});
// Audit
GlobFunctions.AddToAudit(String.Format("Removing standing order : {0}", soid), Session["CustomerCode"].ToString());
}