DataList Columns

  • Thread starter Thread starter MikeB
  • Start date Start date
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();
}
}
 
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();

}

}
 
Back
Top