storing an image into a session variable
I uploaded a picture and added the Url(uploadedImage.FileName) to a database. I then bound a gridview to the dataBase and set the DataImageUrl field to the to the PictureUrl comumn of the database in which the uploadedImage.FileName was stored and so the image is displayed in the gridview(still struggling a bit with controlling the size).
I would just like to know how to add this image info to a session variable so that it can be displayed on a different page. this is what I have done so far(I also added a session["title"] which is easy as it only displays the text value on the other page).
if (e.CommandName == "addToSession") {
//get the row index stored in the CommandArgument property
int index = Convert.ToInt32(e.CommandArgument);
//get the开发者_如何学C 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");
}
Should I add an image button on the other page and try to bind it to the ImageField of the gridview perhaps?
regards
Have took a look at the session string? I never used a grid but I think you cant do that this way... I think the grid will stream the image for you from the database. To access the same image later on without query the db again you will need to store the whole image and not just a link that is no longer valid in the session (as base64 or base128 string) and provide a url that streams the image back.
why not use the session variable to store the url to the image on your server? If you need to display it, just use:
<img src=<%= Session["ImageID"] %>>
精彩评论