开发者

RDLC, showing different images/pictures on different database values, c#

How can I show different pictures based on a value in the database in my rdlc report? for example, costumer - K1, wants picture1, while costumer K2, wants picture2. But I want this value instead to show a picture.

My costumers is insterted into a table. And then sent to the rdlc. This is working so i can fetch the diffrent costumer names, but I want the value 1 开发者_高级运维to show picture 1 while the value 2 shows the picture 2. I have a parameter from my database showing the value in rdlc. If this is not possible any other quick solutions how to show different pictures when the value is different?


You can add a byte array column to the dataset and initialize that column based on the criteria you want. I use this for displaying dynamic graphics based on data in reports.

Bitmap img = new Bitmap(width, height);  // bitmap to display
// paint in the bitmap here

MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);  // save bitmap to a memory stream

dataRow["pictureColumn"] = ms.GetBuffer();

Now, you can set the pictureColum (which is defined as a byte array) as source for your picture object.


Or, if you use Linq to SQL, you can add a property to the partial class of the type in your result set. I use stored procedures for my reports and use this code add a barcode image for an order number:

[Table]
public partial class sp_rpt_wcfResult
{
    public byte[] OrderNumLabel {
        get {
            return
                BarcodeUtilities.ConvertImageToByteArray(
                  BarcodeUtilities.GetBarcodeImage(this.order_number.ToString()),
                  System.Drawing.Imaging.ImageFormat.Bmp);
        }
    }
    ....
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜