2016-06-09 3 views
0

gridview의 ROWCOMMAND에서 다운로드 함수가 호출되었습니다. 그것을 클릭하면 작동하지만, (호출) rowcommand에서 다른 함수를 클릭하면 작동을 멈 춥니 다. 그것은 예외를 던지지 않습니다. 모든 단계를 디버깅했지만 운이 없었습니다.왜 행 명령이 제대로 작동하지 않습니까?

왜?

다운로드 기능 :

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가 : 등록하려면 버튼

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

등록 기능 :

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 : 문제를 해결할 것입니다있는 gridview에 UpdatePanel 컨트롤을 추가 할 수

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

답변

0

시도.

다음 코드를 참조하십시오. 그러면 도움이 될 것입니다.

<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

이 작동하지 않습니다. 죄송합니다 – Cuckoo

+0

다른 방법은 없습니까? – Cuckoo

+0

위의 코드는 각 행의 controlID를 보유하고 있기 때문에 효과가있을 수 있습니다. 코드의 모든 템플릿 필드를 시도 했습니까? –

관련 문제