2011-04-24 66 views
3

我上傳了一張圖片並將Url(uploadedImage.FileName)添加到數據庫中。然後,我將一個gridview綁定到dataBase,並將DataImageUrl字段設置爲存儲uploadedImage.FileName的數據庫的PictureUrl列,因此圖像顯示在gridview中(仍然在控制尺寸上掙扎了一下)。將圖像存儲到會話變量中

我只想知道如何將這個圖像信息添加到會話變量,以便它可以顯示在不同的頁面上。 這是我迄今爲止所做的(我還添加了一個會話[「標題」],這很容易,因爲它只顯示其他頁面上的文本值)。

如果(e.CommandName ==「addToSession」) {

 //get the row index stored in the CommandArgument property 
     int index = Convert.ToInt32(e.CommandArgument); 

     //get the gridview row where the command is raised 
     GridViewRow selectedRow = ((GridView)e.CommandSource).Rows[index]; 

     //values stored in the text propert of the cells 
     string title = selectedRow.Cells[1].Text; 
     string pictureUrl = selectedRow.Cells[3].Text; ???????    
     //set the sesion variable ["Title"] to the title   
     Session["Title"] = title; 

     //this is where i am experiencing some problems 
     Session["ImageID"] = pictureUrl; ??????? 
     Response.Redirect("RateBook.aspx"); 
    } 

我應該添加其他頁面上的圖像按鈕,並嘗試將其綁定到GridView也許是的ImageField?

關於

回答

2

看看會話串嗎?我從來沒有使用網格,但我認爲你不能這樣做......我想網格會從數據庫中爲你流動圖像。要稍後訪問相同的圖像而不再查詢數據庫,您將需要存儲整個圖像,而不僅僅是會話中不再有效的鏈接(如base64或base128字符串),並提供一個將圖像傳回的url。

2

爲什麼不使用會話變量將url存儲到服務器上的映像?如果需要顯示 ,請使用:

<img src=<%= Session["ImageID"] %>>