I'm developing a Dynamic Image Control to be used within a dynamic data site. My worry is with the asp.net image control I will be using as the base control. I want to be able to create this control without having to call another page in order to display
the image. The only input for the asp.net image control is the ImageURL. I will be reading binary data from a database as my source for the image control. However, the only examples I've seen of this create a seperate .aspx page to use as the ImageURL for
the control. I am also worried that this will cause a sizing issue when the control is displayed within the DynamicGridView. Does anyone have any pointers or suggestions to make this development less of a headache?
You can download a sample project that adds new FieldTemplate controls for accessing images from both the database and the file system. If you look in App_Code there is a Photo.cs which shows the proper attributes you need to put on the image field in your
database to get it to display. The control supports scaling the image and will allow uploading of images as well. I plan on having a detailed description of how this project was built and how to use it in my
blog after the holidays.
Here is a link to the sample to use before my blog post is live:
DbImage Sample.
Scott Hunter
ASP.NET Team
http://blogs.msdn.com/scothu
Scott Hunter
PM, ASP.NET Team, Microsoft
Marked as answer by ron.westbrook on Dec 26, 2007 04:16 PM
I think this is going to handle exactly what I needed it to. I'll let you know if I have any trouble and I look forward to your blog after the holidays.
just to add some input ... I've been able to get the image to show up but I guess I'm not able to use the image column as a foreign key ... I get an exception in ForeignKey.ascx saying I can only have STRING values as a foreign key ... so hoping that future
versions support binary data as foreign keys
To make sure there is no misunderstanding, are you using the term 'image' in the 'picture' sense, or in the generic 'binary data' sense? Since you say that you got the image to show up, it sounds like you mean 'picture'. But on the other hand, you also
mention it's a foreign key, which makes it more sense like it's a small amount of binary data (since a picture would not be used as a foreign key). Can you clarify?
column "picture" being binary data, it throws an exception saying the column has to be a string ... and the only other column I have in the table is a primary key integer and it has a problem with that too
I see. Yes, it shouldn't throw an exception. But on the other hand, I'm not sure what you expect to be displayed. It's binary data, so it is generally not easy to get a readable string from it.
Yes, if you had a string column and you don't specify the DisplayColumn("Picture") attribute, then that string column would be used for display by default.
Thank you for you post with example with DbImage DynamicDataField's control. I explored it too - very nice example. But i found two bugs:
1. When we select the same records in table (for example in Categories ) then the OnDataBinding(EventArgs e) don't work in second time and we get in result the list of categories without retrieved images from database into all rows of picture column of our
table.
2. When we start the editing mode of the records but don't select any new picture by Brows button and then press occasionally Update command - the image of our picture disappears from the edited row of our table.
I see that it is not so hard bugs but i tried to find right way to fix it and found that it seems not so easy. Can you fix it into your new issue of blog?
ron.westbroo...
Member
45 Points
19 Posts
Dynamic Image Field
Dec 22, 2007 02:55 PM|LINK
I'm developing a Dynamic Image Control to be used within a dynamic data site. My worry is with the asp.net image control I will be using as the base control. I want to be able to create this control without having to call another page in order to display the image. The only input for the asp.net image control is the ImageURL. I will be reading binary data from a database as my source for the image control. However, the only examples I've seen of this create a seperate .aspx page to use as the ImageURL for the control. I am also worried that this will cause a sizing issue when the control is displayed within the DynamicGridView. Does anyone have any pointers or suggestions to make this development less of a headache?
Thanks,
Software Engineer
Avanade, Inc.
scothu
Participant
1436 Points
291 Posts
Microsoft
Moderator
Re: Dynamic Image Field
Dec 22, 2007 06:47 PM|LINK
Ron,
You can download a sample project that adds new FieldTemplate controls for accessing images from both the database and the file system. If you look in App_Code there is a Photo.cs which shows the proper attributes you need to put on the image field in your database to get it to display. The control supports scaling the image and will allow uploading of images as well. I plan on having a detailed description of how this project was built and how to use it in my blog after the holidays.
Here is a link to the sample to use before my blog post is live: DbImage Sample.
Scott Hunter
ASP.NET Team
http://blogs.msdn.com/scothu
PM, ASP.NET Team, Microsoft
ron.westbroo...
Member
45 Points
19 Posts
Re: Dynamic Image Field
Dec 22, 2007 11:16 PM|LINK
Thanks Scott,
I think this is going to handle exactly what I needed it to. I'll let you know if I have any trouble and I look forward to your blog after the holidays.
Merry Christmas!
Software Engineer
Avanade, Inc.
sandeepprade...
Member
6 Points
6 Posts
Re: Dynamic Image Field
Dec 26, 2007 11:41 AM|LINK
just to add some input ... I've been able to get the image to show up but I guess I'm not able to use the image column as a foreign key ... I get an exception in ForeignKey.ascx saying I can only have STRING values as a foreign key ... so hoping that future versions support binary data as foreign keys
davidebb
Contributor
7006 Points
1366 Posts
Microsoft
Re: Dynamic Image Field
Dec 26, 2007 07:07 PM|LINK
To make sure there is no misunderstanding, are you using the term 'image' in the 'picture' sense, or in the generic 'binary data' sense? Since you say that you got the image to show up, it sounds like you mean 'picture'. But on the other hand, you also mention it's a foreign key, which makes it more sense like it's a small amount of binary data (since a picture would not be used as a foreign key). Can you clarify?
thanks,
David
sandeepprade...
Member
6 Points
6 Posts
Re: Dynamic Image Field
Dec 29, 2007 07:49 PM|LINK
actually what I meant was I can't do this:
[DisplayColumn("Picture")]
column "picture" being binary data, it throws an exception saying the column has to be a string ... and the only other column I have in the table is a primary key integer and it has a problem with that too
davidebb
Contributor
7006 Points
1366 Posts
Microsoft
Re: Dynamic Image Field
Dec 29, 2007 09:22 PM|LINK
I see. Yes, it shouldn't throw an exception. But on the other hand, I'm not sure what you expect to be displayed. It's binary data, so it is generally not easy to get a readable string from it.
David
txghia58
Member
114 Points
32 Posts
Re: Dynamic Image Field
Jan 06, 2008 04:52 AM|LINK
Wouldn't the exception go away if there was at least one character field in the table that holds the picture. Maybe a descriptiion of the picture?
davidebb
Contributor
7006 Points
1366 Posts
Microsoft
Re: Dynamic Image Field
Jan 06, 2008 07:02 AM|LINK
Yes, if you had a string column and you don't specify the DisplayColumn("Picture") attribute, then that string column would be used for display by default.
David
LukCAD
Member
202 Points
48 Posts
Re: Dynamic Image Field
Jan 07, 2008 09:18 PM|LINK
Hi Scott!
Thank you for you post with example with DbImage DynamicDataField's control. I explored it too - very nice example. But i found two bugs:
1. When we select the same records in table (for example in Categories ) then the OnDataBinding(EventArgs e) don't work in second time and we get in result the list of categories without retrieved images from database into all rows of picture column of our table.
2. When we start the editing mode of the records but don't select any new picture by Brows button and then press occasionally Update command - the image of our picture disappears from the edited row of our table.
I see that it is not so hard bugs but i tried to find right way to fix it and found that it seems not so easy. Can you fix it into your new issue of blog?
Thank you a lot again, LukCAD
Dynamic Data