DataList Columns

M

MikeB

I have a datalist with 2 columns (RepeatColumns = 2) that displays photos.
The photo url is based on a value in the Web.Config so I have to set the
url on the databoud event. Although this work fine on the first image, it
doesn't work and the second image and the event doesnt seem to be fired.
Any idea what I am doing wrong or a better way to do this? Below is my
databound method.


protected void dlPhotos_databound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
HyperLink hl = (HyperLink)e.Item.FindControl("HyperLink1");
Image img = (Image)e.Item.FindControl("Image1");

hl.NavigateUrl =
System.Configuration.ConfigurationManager.AppSettings.Get("HostURL") +
"Handler.ashx?Size=O&PhotoID=" +
dlPhotos.DataKeys[e.Item.ItemIndex].ToString() + "&CompanyID=" +
Constants.CompanyID.ToString();
img.ImageUrl =
System.Configuration.ConfigurationManager.AppSettings.Get("HostURL") +
"Handler.ashx?Size=300&PhotoID=" +
dlPhotos.DataKeys[e.Item.ItemIndex].ToString() + "&CompanyID=" +
Constants.CompanyID.ToString();
}
}
 
M

MikeB

I changed my code to this and it started working correctly, thanks for
looking.


protected void dlPhotos_databound(object sender, DataListItemEventArgs e)

{

HyperLink hl = (HyperLink)e.Item.FindControl("HyperLink1");

Image img = (Image)e.Item.FindControl("Image1");

if(hl != null && img != null)

{


hl.NavigateUrl =
System.Configuration.ConfigurationManager.AppSettings.Get("HostURL") +
"Handler.ashx?Size=O&PhotoID=" +
dlPhotos.DataKeys[e.Item.ItemIndex].ToString() + "&CompanyID=" +
Constants.CompanyID.ToString();

img.ImageUrl =
System.Configuration.ConfigurationManager.AppSettings.Get("HostURL") +
"Handler.ashx?Size=300&PhotoID=" +
dlPhotos.DataKeys[e.Item.ItemIndex].ToString() + "&CompanyID=" +
Constants.CompanyID.ToString();

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top