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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top