OnItemDataBound event not firing

G

GOKU24

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top