ImageButton和GridView问题 - 无效的回发

时间:2009-09-18 13:48:09

标签: asp.net gridview imagebutton

我目前有一个Gridview,它使用了一个类型为image的ButtonField,并且可以正常工作。

但是我希望能够使用属于AjaxControlToolkit的ConfirmButtonExtender,它无法在Buttonfield上运行,所以我决定将一个ImageButton放在TemplateField中,但是每当我点击按钮时我都会收到 无效的回发或回调参数 错误。

非常感谢任何建议/意见。谢谢。

新模板字段

            <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>

现有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>

代码

    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 个答案:

答案 0 :(得分:1)

CommandArgument='<% Eval("soid") %>'

应该是

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

请注意“&lt;%#”