By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,423 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

DataList Columns

P: n/a
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.AppSetti ngs.Get("HostURL") +
"Handler.ashx?Size=O&PhotoID=" +
dlPhotos.DataKeys[e.Item.ItemIndex].ToString() + "&CompanyID=" +
Constants.CompanyID.ToString();
img.ImageUrl =
System.Configuration.ConfigurationManager.AppSetti ngs.Get("HostURL") +
"Handler.ashx?Size=300&PhotoID=" +
dlPhotos.DataKeys[e.Item.ItemIndex].ToString() + "&CompanyID=" +
Constants.CompanyID.ToString();
}
}
Jun 2 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.AppSetti ngs.Get("HostURL") +
"Handler.ashx?Size=O&PhotoID=" +
dlPhotos.DataKeys[e.Item.ItemIndex].ToString() + "&CompanyID=" +
Constants.CompanyID.ToString();

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

}

}

"MikeB" <m@nospam.comwrote in message
news:ua*************@TK2MSFTNGP05.phx.gbl...
>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.AppSetti ngs.Get("HostURL") +
"Handler.ashx?Size=O&PhotoID=" +
dlPhotos.DataKeys[e.Item.ItemIndex].ToString() + "&CompanyID=" +
Constants.CompanyID.ToString();
img.ImageUrl =
System.Configuration.ConfigurationManager.AppSetti ngs.Get("HostURL") +
"Handler.ashx?Size=300&PhotoID=" +
dlPhotos.DataKeys[e.Item.ItemIndex].ToString() + "&CompanyID=" +
Constants.CompanyID.ToString();
}
}

Jun 2 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.