Datagrids and User Controls


N

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.
 
Ad

Advertisements

T

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
 

Top