我有一個fileupload控件將圖像上傳到SQL Server 2008數據庫,我想用保存對話框彈出框下載它。下載文件的代碼執行得很好,但是當我點擊下載鏈接按鈕時沒有任何反應。該事件源於後面的代碼。我唯一的猜測是它是導致問題的又一次模式彈出。從ASP.NET C#頁面上的SQL Server下載圖像
<Modalpopup>
</ModalPopup>
<UpdatePanel>
--DetailsView
--------LinkButton(Download)
--DetailsView
</UpdatePanel>
是頁面的結構。
<!-- Details View here -->
<asp:DetailsView ID="dvReviewCases" runat="server" Height="50px"
AutoGenerateRows="False" CssClass="dvCSS"
OnDataBound="dvADReviewCases_DataBound"
onpageindexchanging="dvReviewCases_PageIndexChanging" onitemcommand="dvReviewCases_ItemCommand"
>
<Fields>
<asp:TemplateField HeaderStyle-CssClass="dvHeaderStyle" HeaderText="Evidence" ItemStyle-CssClass="dvValueField" >
<ItemTemplate>
<asp:LinkButton ID="btnDownload" runat="server" Text='<%#Eval("evidenceID") %>' CommandName="Download" >
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
代碼隱藏
// Download file from Evidence table
protected void dvReviewCases_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
if (e.CommandName == "Download")
{
String strCaseID = Session["caseID"].ToString();
String strEvidenceID = Session["evidenceID"].ToString();
//Search for evidence file
DbCommand cmd = GetData.CreateCommand("ADGetEvidence");
GetData.AddParameter(cmd, strEvidenceID, "@evidenceID");
GetData.AddParameter(cmd, strCaseID, "@caseID");
GetData.GetResults(cmd);
// Check if datatable has row returned
if (GetData.getTable().Rows.Count > 0)
{
String fileName = "Evidence" + Session["caseID"].ToString();
byte[] file = null;
String fileType = GetData.getTable().Rows[0][1].ToString();
// Typecast resulting row to byte
file = ((byte[])GetData.getTable().Rows[0][0]);
Response.ContentType = fileType;
// Give user option to download file
Response.AddHeader("Content-Disposition","attachment;filename=" + fileName);
Response.BinaryWrite(file);
Response.End();
}
}
}
我試着加入btnDownload作爲更新面板的觸發器,但它給了我一個錯誤,它無法找到該按鈕時,我跑了頁。 – ReiRei