Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

OnItemDatabound help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Spondishy - 31 Oct 2005 17:16 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.