Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET GDI
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.
   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 3-Jul-12 3:09am
Edited 3-Jul-12 20:03pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
    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!
  Permalink  
v2
Comments
enhzflep at 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 at 3-Jul-12 11:26am
   
Thanks for this - it does look promising. Do you have any asp.net examples?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 520
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 265
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411028.1 | Last Updated 13 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100