OnItemDataBound event not firing

Discussion in 'ASP .Net Building Controls' started by GOKU24, Jul 8, 2003.

  1. GOKU24

    GOKU24 Guest

    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
     
    GOKU24, Jul 8, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jason
    Replies:
    2
    Views:
    5,112
    jason
    Jun 14, 2005
  2. Replies:
    1
    Views:
    1,933
    Brock Allen
    Sep 29, 2005
  3. TS
    Replies:
    14
    Views:
    683
  4. Luigi
    Replies:
    0
    Views:
    473
    Luigi
    Mar 6, 2008
  5. Joey
    Replies:
    0
    Views:
    141
Loading...

Share This Page