Home All Groups Group Topic Archive Search About
Author
8 Jul 2006 8:07 AM
Nicolaj
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

Author
10 Jul 2006 11:52 AM
Teemu Keiski
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




Show quoteHide quote
"Nicolaj" <shri***@gmail.com> wrote in message
news:1152346034.327337.58590@75g2000cwc.googlegroups.com...
>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
>