Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there,

Being new to ASP.Net but ok with winForm I rather naively thought I could create an image button on the fly and put an image on it (rather than an ImageURL).

The problem is this -

I want to create an imagebutton in my gridview. I am placing this in at design time and each row needs a custom image based on some values in the row. No problem with creating the image (using GDi+) but assigning it to the button seems impossible.
VB
Dim B As New ImageButton
B.CommandArgument = "RowNum"
B.CommandName = "AddMerit"
B.ImageUrl = THIS IS WHERE I NEED TO SET THE IMAGE
R.Cells(2).Controls.Add(B)

If ImageButton had an 'image' property then this would be trivial. However, it only has an ImageURL. I suppose that I could create the image, save it on the server and then reference it, but this would be difficult and messy to clean up. I have tried to understand how I might use a webmethod to serve the image, but this also seems expensive for a table of 30-40 rows - I would prefer to set the images before they are sent to the server....

Any help would be appreciated.
Posted
Updated 3-Jul-12 19:03pm
v2

I have found a solution but I cannot believe it is optimal! The solution is to build a complete page with the following code in the page load:
VB
Dim FinalBitmap As Bitmap
Dim NumMerits = Request.Params("Merits").ToString
Dim BarGraphPercent = Request.Params("BarGraph").ToString
Dim msStream As New MemoryStream

 'Code here to populate FinalBitmap with the image

FinalBitmap.Save(msStream, ImageFormat.Png)
Response.ContentType = "image/png"
msStream.WriteTo(Response.OutputStream)

If Not IsNothing(FinalBitmap) Then FinalBitmap.Dispose()

In the main page I then link each row to a "~/Pages/Register/GetGraph?Merits=3&BarGraph=80" (or whatever that student's figures are)

This then results in 30 calls to the server, one for each image. Surely there is a better way than this!
 
Share this answer
 
v2
Comments
enhzflep 3-Jul-12 10:08am    
edit Gday /edit

Sounds like you may benefit from using the Data URI scheme. More here: http://en.wikipedia.org/wiki/Data_URI_scheme
Tim_1024 3-Jul-12 11:26am    
Thanks for this - it does look promising. Do you have any asp.net examples?
I have not really found an acceptable solution - the sub optimal solution works, but the page takes ages to load each image. In the end I created images for each criteria - 400 images - and referenced these.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900