usercontrol in datagrid
I have a usercontrol that contains 5 image buttons. These buttons fire a function when clicked. When the usercontrol is used on a page everything works fine.
I need to use the same usercontrol for each row of a datagrid, after quite a bit of investigation and trial and error I have managed to get the usercontrol to display correctly, by using the itemdatabound function below. The problem is that if you click on any of the buttons the usercontrol not only doesnt perform its required function, but they all disapear. That is the page 'relaods' with no sign of the usercontrols!!! I have other functions on the datagrid for sorting and editing and these are all fine. I am getting desperate and would be most grateful for any advice or suggestions.
Sub dgrdList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim uclButtons As Buttons = DirectCast(LoadControl("../includes/buttons.ascx"), Buttons)
Dim uclType As Type = uclButtons.GetType()
ctlTxthidden = CType(e.Item.FindControl("txtTitleId"), TextBox)
panButtons = CType(e.Item.FindControl("panButtons"), Panel)
Dim strTitle As String
strTitle = ctlTxthidden.Text
Dim strButtShow As String
strButtShow = "st"
uclButtons.setValues(strTitle, strButtShow)
panButtons.Controls.Add(uclButtons)
End If
End Sub
|