2016-06-09 3 views
0

J'ai une fonction de téléchargement appelée dans ROWCOMMAND de gridview. Cela fonctionne quand je clique dessus mais cesse de fonctionner si je clique (appelle) une autre fonction dans rowcommand. Il ne jette pas d'exception. J'ai essayé de déboguer chaque pas mais pas de chance.Pourquoi la commande row row ne fonctionne-t-elle pas correctement?

Pourquoi?

Télécharger Fonction:

public void DownloadFile(string FileName) 
{ 
    try 
    { 
     string filePath = FileName; 
     string fullFilePath = Server.MapPath("../../SiteImages/BPA/" + filePath); 
     Response.Clear(); 
     Response.ClearHeaders(); 
     Response.ClearContent(); 
     Response.AddHeader("Content-Disposition", "attachment; filename=\"" + Path.GetFileName(fullFilePath) + "\""); 
     Response.ContentType = ContentType; 
     Response.TransmitFile(fullFilePath); 
    } 

RowCommand:

protected void grdViewUploadedMaterialOther_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    try 
    { 

     if (e.CommandName == "Download") 
     { 
      mdlImgPreview.Hide(); 

      string FileName = Convert.ToString(e.CommandArgument); 

      DownloadFile(FileName); 

      return; 
     } 

     if (e.CommandName == "View") 
     { 
      imgPreviewed.ImageUrl = "../../SiteImages/BPA/" + e.CommandArgument.ToString(); 
      mdlImgPreview.Show(); 
     } 

    } 
    catch (Exception ex) 
    { 
     ResultLabel.ResultLabelAttributes(ex.Message, ProjectUserControls.Enums.ResultLabel_Color.Red); 
    } 
    finally 
    { 
     ResultPanel.Controls.Add(ResultLabel); 
    } 

RowDataBound: Pour bouton Enregistrer

protected void grdViewUploadedMaterialOther_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     try 
     { 
      LinkButton lb = e.Row.FindControl("btnLinkDownload") as LinkButton; 
      RegisterDownloadButton(lb); 
     } 
     catch (Exception ex) 
     { 
      ResultLabel.ResultLabelAttributes(ex.Message, ProjectUserControls.Enums.ResultLabel_Color.Red); 
     } 
     finally 
     { 
      ResultPanel.Controls.Add(ResultLabel); 
     } 
    } 

Fonction d'enregistrement:

public void RegisterDownloadButton(LinkButton lb) 
    { 
     try 
     { 

      if (lb != null) 
       ScriptManager.GetCurrent(this).RegisterPostBackControl(lb); 


     } 
     catch (Exception ex) 
     { 
      ResultLabel.ResultLabelAttributes(ex.Message, ProjectUserControls.Enums.ResultLabel_Color.Red); 
     } 
     finally 
     { 
      ResultPanel.Controls.Add(ResultLabel); 
     } 
    } 

Gridview:

<asp:GridView runat="server" ID="grdViewUploadedMaterialOther" Width="100%" OnRowDataBound="grdViewUploadedMaterialOther_RowDataBound" 
    OnRowCommand="grdViewUploadedMaterialOther_RowCommand" HeaderStyle-BackColor="#99CC99" 
    DataKeyNames="Pk_UploadedMaterialOther_ID" 
    AutoGenerateColumns="false" 
    CssClass="table table-condensed table-bordered table-striped table-responsive"> 
    <PagerSettings Mode="Numeric" /> 
    <PagerStyle HorizontalAlign="Center" CssClass="gvwCasesPager" /> 
    <Columns> 

     <asp:TemplateField HeaderText="View Attachment"> 
      <ItemTemplate> 
       <asp:LinkButton ID="btnLnkViewAttachment" runat="server" Text="View" CommandArgument='<%# Eval("MaterialPath") %>' CommandName="View"></asp:LinkButton> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Download"> 
      <ItemTemplate> 
       <asp:LinkButton ID="btnLinkDownload" runat="server" Text='<%# Eval("MaterialPath") %>' 
        CommandArgument='<%# Eval("MaterialPath") %>' CommandName="Download"></asp:LinkButton> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Delete"> 
      <ItemTemplate> 
       <asp:ImageButton ID="btnDelete" runat="server" ImageUrl="~/assets/global/images/delete.png" 
        CommandName="cmdDelete" CommandArgument='<%# Container.DataItemIndex %>' 
        ControlStyle-Width="20px" 
        ControlStyle-Height="20px" /> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

Répondre

0

essayer d'ajouter un contrôle UpdatePanel au gridview qui résoudra votre problème.

référez le code suivant, ceci peut vous aider.

<asp:TemplateField HeaderText="Download"> 
     <ItemTemplate> 
      <asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="fileUploadPanel"> 
     <ContentTemplate> 
        <asp:LinkButton ID="btnLinkDownload" runat="server" Text='<%# Eval("MaterialPath") %>' 
          CommandArgument='<%# Eval("MaterialPath") %>' CommandName="Download"></asp:LinkButton> 
     </ContentTemplate> 

        <Triggers> 
         <asp:PostBackTrigger ControlID="btnLinkDownload" /> 
        </Triggers> 
    </asp:UpdatePanel> 
     </ItemTemplate> 
    </asp:TemplateField> 
+0

ne fonctionne pas. désolé – Cuckoo

+0

d'une autre manière? – Cuckoo

+0

le code ci-dessus peut être élaboré, car il contient le controlID de chaque ligne .. avez-vous essayé pour tous les champs de modèle dans votre code .. –