Hi,
I have a datalist control, and in each row I have a label and a
hyperlink control. The label is bound to an id field in the db.
What I'm trying to do is hide the hyperlink if the id is a certain
value.
My question is, does OnItemDataBound fire before actually binding the
controls, as it appears the label has no text (although it should), so
the hyperlink never disappears.
Is there another way of doing this?
Thanks.
Karl Seguin - 31 Oct 2005 17:59 GMT
Ya, ur going about it just a little wrong.
Instead of doing:
Label l = (Label)e.Item.FindControls("someId");
if (l.Text == "0")
{
//hide
}
use the e.Item.DataItem property which gives you access the the underlying
data being bound. So if you are binding to a dataset/dataview/datatable,
you would do:
int id = Convert.ToInt32(((DataRowView)e.Item.DataItem)["SomeId"]);
if (id == 0)
{
e.Item.FindControls("link").Visible = false;
}
Karl

Signature
MY ASP.Net tutorials
http://www.openmymind.net/
> Hi,
>
[quoted text clipped - 11 lines]
>
> Thanks.
Spondishy - 31 Oct 2005 21:04 GMT
Thanks for the response... I knew I'd got this working before.
Appreciated.
> Ya, ur going about it just a little wrong.
>
[quoted text clipped - 38 lines]
> >
> > Thanks.
Cowboy (Gregory A. Beamer) - MVP - 31 Oct 2005 18:11 GMT
In addition to Karl's answer, there is another way. You can build the entire
"data grid" from scratch in code behind. I would only go this route, however,
if it is absolutely necessary, as it is a pain.

Signature
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
> Hi,
>
[quoted text clipped - 11 lines]
>
> Thanks.