2009-09-18 6 views
0

J'ai actuellement un Gridview qui utilise un ButtonField de type image et cela fonctionne.ImageButton et problème GridView - publication invalide

Cependant, je veux être en mesure d'utiliser le ConfirmButtonExtender qui fait partie de la AjaxControlToolkit qui ne peut pas fonctionner sur un ButtonField alors j'ai décidé de placer un ImageButton dans un TemplateField mais chaque fois que je clique sur le bouton je reçois un postback non valide ou argument de rappel erreur.

Des conseils/suggestions seraient grandement appréciés. Je vous remercie.

champ Nouveau modèle

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

existant 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 derrière

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()); 

    } 

Répondre

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

devrait être

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

Notez le "<% #"