Results 1 to 3 of 3

Thread: [RESOLVED] Set Width of Gridvies ASP Image from DB

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Location
    Texas
    Posts
    246

    Resolved [RESOLVED] Set Width of Gridvies ASP Image from DB

    I have a grid view with an asp image control and I'm having a problem setting the width from the database. I have an sql server table that stores the image url and and the image width in a bigInt field. When I try to bind the width of the image control to the field in the table I get an error Specified cast is not valid.

    Can someone help me out with this?

    This is my sql

    Code:
    SELECT        TOP (100) PERCENT BlogId, Title, Body, 
    BlogDate, Deleted, '~/Images/' + ISNULL(ImageUrl, N'Blank.png') AS ImageUrl, 
    ISNULL(Width, 1) AS Width
    FROM            dbo.Blogs
    WHERE        (Deleted = 0) OR  (Deleted IS NULL)
    This is the html for my image control in the item template
    HTML Code:
    <asp:Image ID="Image1" runat="server" CssClass="BlogGridImageRight" 
                 ImageUrl='<%# Eval("ImageUrl") %>' Width='<%# Eval("Width") %>'  />
    I'm using visual studio 2010

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Set Width of Gridvies ASP Image from DB

    Hi,

    Try getting the width value using Unit.Parse Method.

    Code:
    Width='<%# System.Web.UI.WebControls.Unit.Parse(Eval("Width").ToString()) %>'
    -kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Location
    Texas
    Posts
    246

    Re: Set Width of Gridvies ASP Image from DB

    Quote Originally Posted by KGComputers View Post
    Hi,

    Try getting the width value using Unit.Parse Method.

    Code:
    Width='<%# System.Web.UI.WebControls.Unit.Parse(Eval("Width").ToString()) %>'
    -kgc
    Thanks KGComputers,
    That worked! I don't understand exactly why all of that was necessary. I guess I've go a lot to learn.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width