Binding ImageAlign to SQL Database

Discussion in 'ASP.NET / ASP.NET Core' started by annbransom, Dec 16, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. 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!
     
  2. Use ImageAlign='<%#Databinder.Eval(Container.DataItem,"Align")) %>' instead

    Vikram

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. Didn't work. I got this error message:





    Compiler Error Message: BC30944: Syntax error in cast operator; two arguments separated by comma are required.
     
  4. 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
     
  5. 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?
     
  6. 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>
     
  7. I don't know what this means. I am using VB.NET
     
  8. 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
     
  9. 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".
     
  10. So the table column is named "align"?
    And you need to post and retrieve an image via data-binding?

    just confirming...
     
  11. 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.
     
  12. I don't see anything in there about databinding to the ImageAlign property.
     
  13. 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
     
  14. 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
     
  15. 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.
     
  16. Cool, thanks for the response. [​IMG]
     
  17. try something like this...

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


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  18. Thanks! That did the trick! I wonder why that wasn't working on the .NEt image control...
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page