PDA

View Full Version : Binding ImageAlign to SQL Database


annbransom
12-16-2006, 09:40 AM
Hi! I have a column in a SQL table called "align" and it stores either left or right given what a user selects on a form. I then want to bind the ImageAlign property of an image control on a seperate page to display how the user indicated (either left or right). I have tried everything to get this to work, but it just keeps telling me that my input string is in the wrong format! Here is the last thing I tried:




<asp:Image ID="Image1" runat="server" ImageAlign='<%# Eval("Align") %>' ImageUrl='<%# Eval("PicURL") %>' />





Help!

vvsharma
12-17-2006, 08:19 AM
Use ImageAlign='<%#Databinder.Eval(Container.DataItem,"Align")) %>' instead

Vikram

DiscountASP.NET
www.DiscountASP.NET (http://www.discountasp.net/)

annbransom
12-17-2006, 10:50 AM
Didn't work. I got this error message:





Compiler Error Message: BC30944: Syntax error in cast operator; two arguments separated by comma are required.

vvsharma
12-18-2006, 01:07 AM
Try this,


ImageAlign= '<%#Databinder.Eval(Container.DataItem,"Align") %>'


(Sorry for the typo in the previous post-doube closing parenthesis.)


Vikram

DiscountASP.NET
www.DiscountASP.NET (http://www.discountasp.net/)

annbransom
12-18-2006, 04:03 AM
sorry, still didn't work. This time it says that the input string is not in the correct format, which is the error message i've been getting all along. Any other ideas?

wisemx
12-18-2006, 04:53 AM
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmsde2kwrk/html/mypicscssdk.asp

<CODE class=ce><asp:Image id="imgThumbnail"
runat="server" ImageAlign="Middle" ImageUrl="<%# GetImageUrl(Container.DataItem, true) %>">
</asp:Image></CODE><CODE class=ce>protected string GetImageUrl(object dataItem, bool isThumbnail)
{
string imageUrl;
string qstring;

if (isThumbnail)
{
qstring = string.Format("Path={0}&amp;MinRole={1}",
DataBinder.Eval(dataItem, "FullImageThumbPath"),
DataBinder.Eval(dataItem, "MinRole"));
imageUrl = "ShowImage.axd?" + qstring;
}
else
{
qstring = string.Format("Path={0}&amp;MinRole={1}",
DataBinder.Eval(dataItem, "FullImagePath"),
DataBinder.Eval(dataItem, "MinRole"));
imageUrl = "ShowImage.aspx?" + qstring;
}

return imageUrl;
}</CODE>

annbransom
12-18-2006, 05:27 AM
I don't know what this means. I am using VB.NET

wisemx
12-18-2006, 07:37 AM
OK, maybe I didn't fully understand what you needed.

Can you post at least 3 details for your needs and we'll post more accurate code for you.
Salute,
Mark

annbransom
12-18-2006, 07:40 AM
It is getting the image fine. I just need to know how to bind the Align property of the image to a column in my SQL table called "Align".

wisemx
12-18-2006, 07:42 AM
So the table column is named "align"?
And you need to post and retrieve an image via data-binding?

just confirming...

annbransom
12-18-2006, 08:03 AM
Yes. The image URL is stored in a column called "PicURL". It is getting the image fine. The align column is called "Align". Each entry is either "left" or "right". This is where I can't get it to work. It is binding to the ImageURL fine, just not the ImageAlign property.

wisemx
12-18-2006, 10:20 AM
OK, see if this page helps a bit:
http://msconline.maconstate.edu/tutorials/ASPNET20/ASPNET04/aspnet04-03.aspx

annbransom
12-18-2006, 10:46 AM
I don't see anything in there about databinding to the ImageAlign property.

wisemx
12-19-2006, 01:06 AM
That one was just for formatting the image control in ASP.NET 2.

Look on the left side and you can find a lot of data examples:
http://msconline.maconstate.edu/tutorials/ASPNET20/default.htm

If you don't find it there search MSDN for a few examples.
http://msdn2.microsoft.com/en-us/asp.net/default.aspx

joelnet
12-20-2006, 01:11 AM
I'm guessing the attribute doesn't accept a string, or the string you are entering isn't exactly the same as what it was expecting.



Joel Thoms
DiscountASP.NET
http://www.DiscountASP.NET

wisemx
12-20-2006, 01:27 AM
Ann, can you expand on this a bit? Just out of curiosity...


Are you storingimages in the Database?
If yes, was there a reason to do that rather than storing thepathfor image locations?

btw, CodeGuru did a nice little article about data binding ASP.NET 2.0 controls last month:
http://www.codeguru.com/csharp/.net/net_asp/controls/article.php/c12821/

All the best,
Mark

annbransom
12-20-2006, 03:53 AM
I am just storing image paths in a SQL database. I also wanted to allow the user to store alignment in the database, so they would have a little more control over how the image appeared on the webpage. It was for a sort of "mini-blog" system.

wisemx
12-20-2006, 04:29 AM
Cool, thanks for the response. http://community.discountasp.net/emoticons/wink.gif

joelnet
12-20-2006, 12:03 PM
try something like this...

<imgsrc='<%# Eval("PicURL") %>' align='<%# Eval("Align") %>'/>


Joel Thoms
DiscountASP.NET
http://www.DiscountASP.NET

annbransom
12-20-2006, 12:48 PM
Thanks! That did the trick! I wonder why that wasn't working on the .NEt image control...