I currently have a Gridview which uses a ButtonField of type image and this works.
我目前有一个使用类型图像的ButtonField的Gridview,这是有效的。
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.
但是我希望能够使用作为AjaxControlToolkit的一部分的ConfirmButtonExtender,它不能在Buttonfield上运行,所以我决定将一个ImageButton放在TemplateField中,但是每当我点击按钮时我都会收到一个无效的回发或回调参数错误。
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
现有的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());
}
1 个解决方案
#1
1
CommandArgument='<% Eval("soid") %>'
should be
应该
CommandArgument='<%# Eval("soid") %>'
Note the "<%# "
注意“<%#”
#1
1
CommandArgument='<% Eval("soid") %>'
should be
应该
CommandArgument='<%# Eval("soid") %>'
Note the "<%# "
注意“<%#”