posted on Thursday, May 20, 2004 10:29 AM
by
warstar
ItemDataBound stupid mistake between e.Item.ItemIndex and e.Item.DataSetIndex
Hi there :)
Ok yet again a small problem :(
I had a very nice datagrid with info in it a ItemDataBound to show the pricture the right way and it was great :D
But then there came the evil paging *i was scared* and when i went to page to the images wheren't right anymore!!
There was no darn reson i could find.......
The code with the error:
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex >= 0)
{
string ID = dataSetProduct1.product[e.Item.ItemIndex].productID.ToString();
HyperLink picture = e.Item.FindControl("img_product") as HyperLink;
picture.ImageUrl = string.Format("/Picture/Product/Tumb/{0}.jpg",ID);
}
}
And then i found the problem it was e.Item.ItemIndex dam wat was i stupid the problem was that i looked at the row of the datalist and not to the row of the dataset witch can be gotten by using e.Item.DataSetIndex and now i works like a speed ass again :p
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex >= 0)
{
string ID = dataSetProduct1.product[e.Item.DataSetIndex].productID.ToString();
HyperLink picture = e.Item.FindControl("img_product") as HyperLink;
picture.ImageUrl = string.Format("/Picture/Product/Tumb/{0}.jpg",ID);
}
}
Happy Netting