473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

datalist and OnItemDatabound

Hey all. I think this should be a simple question for many of you. I
have a simple guestbook type of page I'm making with asp.net/vb.net.
It's generally going well, but I want to give visitors the option of
hiding their email addresses. I've got a boolean field in my (very
simple) table to indicate the state of a checkbox the user can check.

So I've created an OnItemDatabound event tied to my Datalist that
displays the guestbook entries. My event looks like this:

-----------------
Protected Sub dlGuests_DataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
If e.Item.DataItem("hide_email") Then
e.Item.DataItem("email") = "<i>hidden</i>"
End If
End If
End Sub
-----------------

If I step through it the code is executing, and I do hit my condition
(If e.Item.DataItem("hide_email")) which then executes the code that I
thought would change the email address text to thew word "hidden".

But the email address still displays. What am I doing wrong? I suspect
it's the assignment of e.Item.DataItem("email") but I swear I've done
that successfully in the past.

Thanks!

Matt
Nov 19 '05 #1
2 2075
This won't work because the DataBoudn event fires after the control has already
been built from the data source. You want to get a reference to the control
and change its data/properties directly.

Dim l as Label = CType(e.Item.FindControl("EmailControlID"), Label)
l.Text = "hidden";
l.ControlStyle.Font.Italic = true

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hey all. I think this should be a simple question for many of you. I
have a simple guestbook type of page I'm making with asp.net/vb.net.
It's generally going well, but I want to give visitors the option of
hiding their email addresses. I've got a boolean field in my (very
simple) table to indicate the state of a checkbox the user can check.

So I've created an OnItemDatabound event tied to my Datalist that
displays the guestbook entries. My event looks like this:

-----------------
Protected Sub dlGuests_DataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
If e.Item.DataItem("hide_email") Then
e.Item.DataItem("email") = "<i>hidden</i>"
End If
End If
End Sub
-----------------
If I step through it the code is executing, and I do hit my condition
(If e.Item.DataItem("hide_email")) which then executes the code that I
thought would change the email address text to thew word "hidden".

But the email address still displays. What am I doing wrong? I suspect
it's the assignment of e.Item.DataItem("email") but I swear I've done
that successfully in the past.

Thanks!

Matt


Nov 19 '05 #2
Thanks!

Matt

Brock Allen wrote:
This won't work because the DataBoudn event fires after the control has
already been built from the data source. You want to get a reference to
the control and change its data/properties directly.

Dim l as Label = CType(e.Item.FindControl("EmailControlID"), Label)
l.Text = "hidden";
l.ControlStyle.Font.Italic = true

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hey all. I think this should be a simple question for many of you. I
have a simple guestbook type of page I'm making with asp.net/vb.net.
It's generally going well, but I want to give visitors the option of
hiding their email addresses. I've got a boolean field in my (very
simple) table to indicate the state of a checkbox the user can check.

So I've created an OnItemDatabound event tied to my Datalist that
displays the guestbook entries. My event looks like this:

-----------------
Protected Sub dlGuests_DataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
If e.Item.DataItem("hide_email") Then
e.Item.DataItem("email") = "<i>hidden</i>"
End If
End If
End Sub
-----------------
If I step through it the code is executing, and I do hit my condition
(If e.Item.DataItem("hide_email")) which then executes the code that I
thought would change the email address text to thew word "hidden".

But the email address still displays. What am I doing wrong? I suspect
it's the assignment of e.Item.DataItem("email") but I swear I've done
that successfully in the past.

Thanks!

Matt


Nov 19 '05 #3

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

Similar topics

8
by: Nevyn Twyll | last post by:
I have a multi-level datalist setup: DataList1 DataList2 MyGrid I have columns explicitly defined for the grid in the html. Sometimes, On the initial Load() of the Page, I want to add extra...
3
by: Stimp | last post by:
I have a datalist that outputs a link to a picture in each ItemTemplate: e.g. <asp:DataList id="DataList1" ...etc> <ItemTemplate> <a href='Pic.aspx?pic=somenumber'>picture</a> </ItemTemplate>...
8
by: bienwell | last post by:
Hi, I have a problem of displaying data bound by a datalist control. In my table, I have a field Start_date which has Short Date data type. I tried to update this field by Current Date. After...
3
by: GD | last post by:
I'm using a DataList and a Repeater (nested in the DataList) to display a list of "Chapters" and "Documents" within the Chapters. <asp:DataList ID="dlChapter" Runat="server" RepeatColumns="2"...
5
by: Vikas Kumar | last post by:
i had coded like this <ItemTemplate> <table width="100%"> <tr width="100%"> <td width="25%"><%#DataBinder.Eval(Container.DataItem,"FName")%></td> <td width="25%"><input type=text ...
3
by: mroffey | last post by:
Hi everyone, I've been having this problem and I've searched high and low, but I can't seem to find the answer to what is probably a very simple solution. In a nutshell, I have a nested...
1
by: jobo | last post by:
Hello, I'm trying to assign a NavigateURL in my HyperLink in my DataList from the backend. Here's my code: <asp:DataList id="ItemsList" OnItemDataBound="oidb" BorderColor="black"...
0
by: jobo | last post by:
Hello, I'm trying to test out a DataList I made but I'm getting a bunch of errors that say "Expected class, delegate, enum, interface, or struct" Visual Studio says that those errors are...
1
by: terminul | last post by:
Hi I have a datalist which loops through the categories and within the datalist I have a CheckBoxList which are bound on the DataList's OnItemDataBound. The only problem I have is retrieving...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.