Datagrids and User Controls

Discussion in 'ASP .Net Web Controls' started by Nicolaj, Jul 8, 2006.

  1. Nicolaj

    Nicolaj Guest

    I have a datagrid in a user control with specific properties of the
    datagrid exposed which I have used in many different aspx pages. I also
    have the itemdatabound event handled in the user control.

    I now need to change the OnItemDataBound event of the grid for a
    couple of pages. Is there any way of doing so ( akin to "overriding"
    the event in the page the user control resides ). I hope this makes
    sense.

    ---------
    Nicolaj
    Nicolaj, Jul 8, 2006
    #1
    1. Advertising

  2. Nicolaj

    Teemu Keiski Guest

    Hi,

    basically you could define Grid_ItemDataBound (name it as you like) event in
    the user control, declare it similarly as ItemDataBound is declared. Just
    raise that event when ItemDataBound in the grid raises (pass event arguments
    also), so Page could handle if it needs to the event
    Here's a small sample:

    'In the UC

    Partial Class WebUserControl2
    Inherits System.Web.UI.UserControl

    Public Event Grid_ItemDataBound As DataGridItemEventHandler

    Protected Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    DataGrid1.ItemDataBound
    'Passing reference to DataGrid also
    RaiseEvent Grid_ItemDataBound(Me.DataGrid1, e)
    End Sub
    End Class


    'On the page:L ID of the UC is WebUC2

    Protected Sub MyUC2_Grid_ItemDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles
    MyUC2.Grid_ItemDataBound

    End Sub

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke




    "Nicolaj" <> wrote in message
    news:...
    >I have a datagrid in a user control with specific properties of the
    > datagrid exposed which I have used in many different aspx pages. I also
    > have the itemdatabound event handled in the user control.
    >
    > I now need to change the OnItemDataBound event of the grid for a
    > couple of pages. Is there any way of doing so ( akin to "overriding"
    > the event in the page the user control resides ). I hope this makes
    > sense.
    >
    > ---------
    > Nicolaj
    >
    Teemu Keiski, Jul 10, 2006
    #2
    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. Zi
    Replies:
    0
    Views:
    429
  2. Craig G
    Replies:
    1
    Views:
    289
    Shiva
    Nov 11, 2004
  3. =?Utf-8?B?TW9vampvbw==?=

    Using user controls in datagrids

    =?Utf-8?B?TW9vampvbw==?=, Jul 8, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    381
    Scott Allen
    Jul 8, 2005
  4. Zi

    User Controls with in datagrids

    Zi, Oct 2, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    150
  5. Siegfried Heintze

    Wanted: Samples Fancy Controls and Datagrids

    Siegfried Heintze, Sep 23, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    92
    Siegfried Heintze
    Sep 23, 2003
Loading...

Share This Page