我正在 Telerik:RadGrid 中加載資料,但我有一列未加載,其中包括檔案(二進制資料)。
正如您在影像中看到的那樣,此列沒有加載資料庫內容,而是只加載System.Byte:

注意在上面我們不僅保存了檔案名,而且還保存了“我的”型別。.net 4.5(或更高版本)有一個名為 GetMineType 的內置函式 - 您可以將檔案名傳遞給它,它會生成正確的礦井型別。
因此,在上面,當您單擊“影像按鈕”時,我們將使用以下代碼從資料庫中獲取位元組,并將其發送給客戶端:
protected void cmdExcel_Click(object sender, ImageClickEventArgs e)
{
ImageButton btn = (ImageButton)sender;
GridViewRow gRow = (GridViewRow)btn.Parent.Parent;
int PKID = (int)GridView1.DataKeys[gRow.RowIndex]["ID"];
// get data from table
DataRow rstData = MyRst("SELECT FileB, FileName, MineType from tblFiles where ID = " PKID).Rows[0];
Byte[] binFile = (Byte[])rstData["FileB"];
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = rstData["MineType"].ToString();
Response.AddHeader("Content-Disposition", "inline; filename=" rstData["FileName"]);
Response.BinaryWrite(binFile);
Response.End();
}
As noted, most grids, be they gridview, list view or that telerick grid should work similar. So you don't include the bytes() data in the grid, but allow a button click, and stream down (send) the byte file to the client.
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/339814.html
