Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Building Controls (http://www.velocityreviews.com/forums/f59-asp-net-building-controls.html)
-   -   OnItemDataBound event not firing (http://www.velocityreviews.com/forums/t755512-onitemdatabound-event-not-firing.html)

GOKU24 07-08-2003 08:05 PM

OnItemDataBound event not firing
 
I am creating a Templated Data-Bound control. When the DataBind()
method is called I would like the OnItemDataBound to fire. I can tell
something is happening because the control is printing the bullets
where text would go, but not the actual text. When I use <%# %>
syntax the control instead of the labels the control works.
Unfortunately, this will not give me the desired format. Here is the
code being used for this:

//The Server Control
<mycrt:databoundcontrol id="rptUpcomingTraining"
OnItemDataBound="rptUpcomingTraining_ItemDataBound " runat="server">
<ItemTemplate>
<tr>
<td class="bullet" valign="top">&gt;</td>
<td valign="top">
<asp:Label ID="lblUpcomingTraining" Runat="server" />
<asp:Label Font-Bold="True" ID="lblClassDates" Runat="server"
Visible="True" />
</td>
</tr>
</ItemTemplate>
</mycrt:databoundcontrol>


//The rptUpcomingTraining_ItemDataBound function
protected void rptUpcomingTraining_ItemDataBound(object s,
NIHCMSBusinessObjectLibrary.NIHCMSDataBoundControl .DataBoundItemEventArgs
e)
{

try
{
DbDataRecord dbr = (DbDataRecord)e.Item.DataItem;

((Label)e.Item.FindControl("lblUpcomingTraining")) .Text =
Convert.ToString(DataBinder.Eval(dbr, "Title")) + "<br>";

if( Convert.ToString(DataBinder.Eval(dbr, "ClassDate")).Length >
0)
{
((Label)e.Item.FindControl("lblClassDates")).Text +=
Convert.ToString(DataBinder.Eval(dbr, "ClassDate","{0:M}")) +
"&nbsp;&nbsp;";
}

if( Convert.ToString(DataBinder.Eval(dbr, "ClassDate1")).Length >
0)
{
((Label)e.Item.FindControl("lblClassDates")).Text +=
Convert.ToString(DataBinder.Eval(dbr, "ClassDate1","{0:M}")) +
"&nbsp;&nbsp;";
}

if( Convert.ToString(DataBinder.Eval(dbr, "ClassDate2")).Length >
0)
{
((Label)e.Item.FindControl("lblClassDates")).Text +=
Convert.ToString(DataBinder.Eval(dbr, "ClassDate2","{0:M}")) +
"&nbsp;&nbsp;";
}

if( Convert.ToString(DataBinder.Eval(dbr, "ClassDate3")).Length >
0)
{
((Label)e.Item.FindControl("lblClassDates")).Text +=
Convert.ToString(DataBinder.Eval(dbr, "ClassDate3","{0:M}"));
}

((Label)e.Item.FindControl("lblClassDates")).Text += "<br><br>";
}
catch(Exception E)
{
((Label)e.Item.FindControl("errMessage")).Text =
E.Message.ToString()+"\n";
}
}


//Code for OnItemDataBound Event
#region Events

protected override bool OnBubbleEvent(object source, EventArgs e)
{
// Handle events raised by children by overriding OnBubbleEvent.

bool handled = false;

if (e is DataBoundItemEventArgs)
{
DataBoundItemEventArgs ce = (DataBoundItemEventArgs)e;

RaiseBubbleEvent(this, ce);
handled = true;
}

return handled;
}

protected virtual void OnItemDataBound(DataBoundItemEventArgs e)
{
DataBoundItemEventHandler onItemDataBoundHandler =
(DataBoundItemEventHandler)Events[EventItemDataBound];
if (onItemDataBoundHandler != null) onItemDataBoundHandler(this, e);
}

[
Category("Behavior"),
Description("Raised when an item is data-bound.")
]
public event DataBoundItemEventHandler ItemDataBound
{
add
{
Events.AddHandler(EventItemDataBound, value);
}
remove
{
Events.RemoveHandler(EventItemDataBound, value);
}
}

//public delegate void DataBoundItemCommandEventHandler(object source,
DataBoundItemCommandEventArgs e);
public delegate void DataBoundItemEventHandler(object sender,
DataBoundItemEventArgs e);

public sealed class DataBoundItemEventArgs : EventArgs
{

private DataBoundItem item;

public DataBoundItemEventArgs(DataBoundItem item)
{
this.item = item;
}

public DataBoundItem Item
{
get
{
return item;
}
}
}

#endregion



I hope this makes sense. Please let me know if you need more info.
Thanks in advance for your time.

-T


All times are GMT. The time now is 10:11 AM.

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