C
Chris
I am dynamically adding a user control to each row in a gridview. The reason
I am doing it dynamically is the user control is different depending on
certain data in the gridview. The gridview contains a placeholder and I add
the control to it, the user control is a formview bound to an object
datsource. This works great until I post back the page and the user control
disappears. What am I doing wrong? Regards, Chris.
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim o As ObjectDataSource = CType(e.Row.FindControl("objdsgetorders"),
ObjectDataSource)
o.SelectParameters(0).DefaultValue =
GridView1.DataKeys(e.Row.DataItemIndex).Value
Dim pl As PlaceHolder = CType(e.Row.FindControl("plchildgw"), PlaceHolder)
Dim ctl As Control = LoadControl("updateorder.ascx")
Dim odssub As ObjectDataSource = CType(ctl.FindControl("odscustomer"),
ObjectDataSource)
odssub.SelectParameters("customerid").DefaultValue =
CInt(GridView1.DataKeys(e.Row.DataItemIndex).Value)
pl.Controls.Add(ctl)
End If
End Sub
I am doing it dynamically is the user control is different depending on
certain data in the gridview. The gridview contains a placeholder and I add
the control to it, the user control is a formview bound to an object
datsource. This works great until I post back the page and the user control
disappears. What am I doing wrong? Regards, Chris.
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim o As ObjectDataSource = CType(e.Row.FindControl("objdsgetorders"),
ObjectDataSource)
o.SelectParameters(0).DefaultValue =
GridView1.DataKeys(e.Row.DataItemIndex).Value
Dim pl As PlaceHolder = CType(e.Row.FindControl("plchildgw"), PlaceHolder)
Dim ctl As Control = LoadControl("updateorder.ascx")
Dim odssub As ObjectDataSource = CType(ctl.FindControl("odscustomer"),
ObjectDataSource)
odssub.SelectParameters("customerid").DefaultValue =
CInt(GridView1.DataKeys(e.Row.DataItemIndex).Value)
pl.Controls.Add(ctl)
End If
End Sub