ListView ItemTemplate LinkButton

2 posts, 0 answers
  1. Rayne
    Rayne avatar
    254 posts
    Member since:
    Sep 2010

    Posted 16 Mar 2011 Link to this post

    I'm having trouble with my ListView. I've got a linkButton in the ItemTemplate and I want to set the onClientClick to run a javascript function, but it needs a parameter value from the Item Data.

    I was thinking that I need to use the ItemDataBound event to add the attribute since the OnClientClick doesn't properly convert my Eval command.

    I'm just not quite sure how to do this.

    Here is my code so far:
    LinkButton btn = (LinkButton)e.Item.FindControl("PhotoLinkButton");
    string id = DataBinder.Eval(e.Item, "PhotoID").ToString();
    btn.Attributes.Add("onclick", string.Format("viewImage({0}); return false;", id));

    I know the code in line 2 isn't right. I'm new to ASP.NET and AJAX, so I'm trying to pick it up as I go.

    What I'm trying to accomplish is the pretty much the same as the demo for the ListView Gallery (with the images that when clicked open a new window with the full size image. My images are stored in the database, so there is no height and width info. My database only has the original filename, the contents (image datatype), plus some other metadata. There is no restriction on the image's size or dimensions, so it could be a very large image. I was hoping to set a default size on the window and have the image auto-resize to fit (similar to what Internet Explorer does when you open an image larger than the browser's window size).

    Any guidance as to how I can do this would be appreciated. If there is a better way, I'm all for it. Oh yeah, my datasource is a SQLDataSource in DataSet Mode, not an ObjectDataSource. That's where I got stuck when trying to use the demo as a starting point.
  2. Mira
    Mira avatar
    1124 posts

    Posted 21 Mar 2011 Link to this post

    Hello Rayne,

    In order to access the PhotoID, I recommend that you use the approach from the Accessing Controls in RadListView help topic.

    To make the window automatically resize itself according to its content, please set the AutoSize property to true.

    I hope this helps.

    the Telerik team
Back to Top