Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   datalist and OnItemDatabound (http://www.velocityreviews.com/forums/t99495-datalist-and-onitemdatabound.html)

MattB 03-28-2005 10:52 PM

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

Brock Allen 03-28-2005 11:12 PM

Re: datalist and OnItemDatabound
 
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
>





MattB 03-28-2005 11:18 PM

Re: datalist and OnItemDatabound
 
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
>>

>
>
>



All times are GMT. The time now is 08:56 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.