HighTechTalks DotNet Forums  

OnItemDataBound event not firing

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss OnItemDataBound event not firing in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default OnItemDataBound event not firing - 07-08-2003 , 04:05 PM






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

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.