473,651 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OnItemDatabound help

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.

Nov 19 '05 #1
3 970
Ya, ur going about it just a little wrong.

Instead of doing:

Label l = (Label)e.Item.F indControls("so meId");
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.FindCont rols("link").Vi sible = false;
}

Karl

--

MY ASP.Net tutorials
http://www.openmymind.net/

"Spondishy" <sp*******@tisc ali.co.uk> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.com...
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.

Nov 19 '05 #2
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.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** ************
Think Outside the Box!
*************** ************
"Spondishy" wrote:
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.

Nov 19 '05 #3
Thanks for the response... I knew I'd got this working before.

Appreciated.

Karl Seguin wrote:
Ya, ur going about it just a little wrong.

Instead of doing:

Label l = (Label)e.Item.F indControls("so meId");
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.FindCont rols("link").Vi sible = false;
}

Karl

--

MY ASP.Net tutorials
http://www.openmymind.net/

"Spondishy" <sp*******@tisc ali.co.uk> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.com...
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.


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1991
by: Antonio D'Ottavio | last post by:
Good morning, I've a problem with a dropdownlist located inside any row of a datalist, I fill both datalist and dropdownlist at runtime, the problem is with the dropdownlist infact using the event OnItemDataBound I can fill it but it is impossible for me to load the right selectedItem.Value , infact looking at the html page produced by the server I've this strange code : <select name="MyDataCampi:_ctl1:ComboTipoPartita"...
0
1102
by: vincent | last post by:
Hello, How do i get the last row OnItemDataBound in Datagrid or atleast the number of rows OnItemDataBound in Datagrid? thanks Vincent
0
1754
by: ItNerd | last post by:
The following code causes two letters to be highlighted at once, so for example, if you click on Division 2 letter 'A', the letter 'A' in Division 1 is also highlighted. I want only one letter highlighted, and I wand the proper division number to be highlighted alone, as well. It seems that because the letters bound to the letterList datalist in a nested datalist, I cannot call the onitemdatabound event on one hyperlink only, because...
4
1819
by: Anders | last post by:
Hi, I was wondering what is most efficient of the two. Is it more efficient to add server controls within the Itemtemplate and use OnItemDataBound to manipulate and databind the servercontrols. Or is better to send the DataItems via. a method/function from within the Itemtemplate (<%# call function %>) Id love to hear your thoughts. Anders
2
2665
by: jason | last post by:
i'm trying to set the commandargument property of a buttoncolumn in the DataGrid ItemBind event. it works fine in one instance, but in the latest page i've written it doesn't seem to work, and i can't see why. can anyone tell me why this chunk of code works: <asp:datagrid id="DataGrid1" style="Z-INDEX: 104; LEFT: 16px; POSITION: absolute; TOP: 136px" runat="server" CellPadding="3" OnItemDataBound="DataGridBindEvent"...
2
1996
by: Girish | last post by:
Hello all, Im wondering why my OnItemDataBound gets fired twice here. I got this sample code from somewhere online.. and when I put a break point in the method... it hits the method twice for each row rendered... Any insights?? Thanks! Girish
1
1514
by: rmccinc | last post by:
OK, I am running into some issues that I cant figure out a work-around. I am not going to post code cause I figured out WHY my issue is happening: -I have a datagrid, and a button that fires a click event. -The Datagrids onitemdatabound event dynamically creates validation controls per values from other columns in the datagrid, one of those controls is a textbox and it is the ControlToValidate of the validation control.
1
1150
by: Mikeon | last post by:
Hello! I have a problem customizing the databound controls using the OnItemDataBound event. The code below is an example of what I'm trying to do. I have a datasource and basing on the data I want to customize the cells in the DataList for example by setting the CssClass property. Everything works fine the first time, but on PostBack the OnItemDataBound does not fire because the datasource is only bound when !IsPostBack and the...
14
8668
by: TS | last post by:
I have this custom data list control and i override the onItemDatabound event. After upgrading to vs 2005, this event is not always getting called, though it does at other times. No changes were made when upgrading to 2.0 is there any reason for this because of .net 2.0? thanks
0
1653
by: Brian Lowe | last post by:
I'm in a web page and I have hierarchical data so I'm using 2 nested DataList controls. DataList1 is using a data source with rows of , , and where MoreData is a list. DataList1 has an ItemTemplate with Literal controls for Name, ID and Status and a DataList control for MoreData. DataList2 is using MoreData where fields are , and .
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8695
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8460
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.