This is a migrated thread and some comments may be shown as answers.

ListView ItemTemplate LinkButton

1 Answer 155 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Rayne
Top achievements
Rank 1
Rayne asked on 16 Mar 2011, 08:12 PM
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.

1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 21 Mar 2011, 12:50 PM
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.

Greetings,
Mira
the Telerik team
Tags
ListView
Asked by
Rayne
Top achievements
Rank 1
Answers by
Mira
Telerik team
Share this question
or