PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

Datalist ItemDataBound modification

 
 
mplutodh1
Guest
Posts: n/a
 
      5th Aug 2005
I am trying to work with the ItemDataBound property of the DataList to
modify the display for a page that lists future events. Here is the
code:

Sub OnItemDataBound(ByVal sender As Object, e As
DataListItemEventArgs)

If e.Item.ItemType = ListItemType.Item OR e.Item.ItemType =
ListItemType.AlternatingItem then
Dim bolOnline as Boolean =
Convert.ToBoolean(DataBinder.Eval(e.Item.DataItem, "bolReg"))
Dim lblReg As Label
If bolOnline then
lblReg.text = "<a href='registration.aspx?EventID="&
DataBinder.Eval(e.Item.DataItem, "EventID")&"'>Register Online!</a>"
Else
lblReg.text = "Call to Register"
End if
End If

End Sub

I know this probably isn't going to work because I can't have multiple
labels named the same thing, but maybe this gives the idea of what I am
trying to accomplish. If bolReg = true in the database I need a link to
be displayed to take the user to a registration page, but if bolReg =
false then no link should be displayed and it should state Call to
Register.

There are about numerous events that are displayed in the datalist and
each one may or may not have online registration (ie bolReg = true or
false)

Anyone have suggestions on how to tackle this or where I am going
wrong? Right now nothing is being printed out, even if I do a
response.write in the If bolOnline statement.

Thanks in advance

-Matt

 
Reply With Quote
 
 
 
 
=?Utf-8?B?RWx0b24gVw==?=
Guest
Posts: n/a
 
      5th Aug 2005
Hi Matt,

What I mean is to use field name (or field index) to retrieve data from
DataRowView. For example, your sql query is

SELECT bolReg, EventID FROM YOUR_TABLE

Then

Dim bolOnline As Boolean = drv(“bolReg”) ‘ or drv(0)
Dim eventID As String = drv(“EventID”) ‘ or drv(1)

And any web controls you use to show data of DataList should be in the
DataList, e.g. you should build a label in the datalist:

aspataList id="dataList" runat="server" RepeatDirection=Vertical >
<ItemTemplate>
<asp:Label Runat=server ID="lblReg "></asp:Label>
</ItemTemplate>
</aspataList>

then you can use following code to refer to it:

Dim lblReg As Label = CType(e.Item.FindControl(“lblReg”), Label)

HTH

Elton

"mplutodh1" wrote:

> Elton,
>
> I am confused as to how that is much different from what I was doing?
> First of all is the addition of _col_ID to the end of bolOnline
> something new that I am missing?
>
> The fields in the table are (bolReg) which is a Yes/No for being online
> reg or not.
> Then the registration ID (EventID) is used in the URL for the
> registration. Beyond that there are no other fields I am working with
> in the DB. I don't see what demensioning a lblReg to = lblReg_ID has
> anything to do with what is in the DB?
>
> Sorry for being confused, just don't really see what you are trying to
> show me. I don't know how i "need find out lblReg built in datalist"
> rather than declaring it.
>
> Sorry! Thanks for the help.
> -Matt
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with DataList's ItemDataBound Event Nathan Sokalski Microsoft ASP .NET 2 27th May 2007 08:44 AM
DataList ItemDataBound TheDude5B Microsoft ASP .NET 0 21st Feb 2007 01:53 PM
ItemDataBound text modification question =?Utf-8?B?QmVuIFIu?= Microsoft Dot NET 3 8th Jun 2005 01:50 AM
ItemDataBound text modification? =?Utf-8?B?QmVuIFIu?= Microsoft Dot NET 0 31st May 2005 03:33 PM
Using AddHandler in a DataList ItemDataBound event =?Utf-8?B?U2NvdHQ=?= Microsoft Dot NET 0 19th Apr 2004 03:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:52 AM.