J
Jerry C
I am trying to use the template builder in a Web part. this code runs but no
control in the Template column. this is the CreateChildControls Sub from Form
4 of a sample from MSDN "Introducing the ASP.NET 2.0 Web Parts Fromework"
modifyed to try to add a grid view and custom columns to the control. The
grid shows ok and there is data in it and the bound field and Connand field
is OK.
This is the code.
Protected Overrides Sub CreateChildControls()
'Create the GridView
Controls.Clear()
grdTree = New GridView
grdTree.AutoGenerateColumns = True
grdTree.EmptyDataText = "There is no data today"
grdTree.ID = "gvTree"
grdTree.Attributes.Add("runat", "server")
grdTree.Width = 100%
'Try the TemplateField field is created and the header Text is OK
'but there is no DropDownList box in the field.
Dim grdTF As New TemplateField
grdTF.HeaderText = "Checkbox Template Field"
Dim ddlBox As New DropDownList
ddlBox.ID = "ddltop"
ddlBox.Visible = True
ddlBox.Items.Add("One")
ddlBox.Items.Add("Two")
Dim CT As New Control
CT.Controls.Add(ddlBox)
Dim grdTB As New TemplateBuilder
grdTF.ItemTemplate = grdTB
grdTF.ItemTemplate.InstantiateIn(CT)
grdTree.Columns.Add(grdTF)
'CommandField works OK.
Dim grdCF As CommandField = New CommandField
grdCF.ShowSelectButton = True
grdTree.Columns.Add(grdCF)
'BoundField works OK.
Dim grdBF As BoundField = New BoundField
grdBF.DataField = "ProductID"
grdTree.Columns.Add(grdBF)
Dim productTable As New DataTable()
Dim dad As New SqlDataAdapter(selectString, _
connectionString)
dad.Fill(productTable)
grdTree.DataSource = productTable
grdTree.DataBind()
Me.Controls.Add(grdTree)
End Sub
Thank you,
control in the Template column. this is the CreateChildControls Sub from Form
4 of a sample from MSDN "Introducing the ASP.NET 2.0 Web Parts Fromework"
modifyed to try to add a grid view and custom columns to the control. The
grid shows ok and there is data in it and the bound field and Connand field
is OK.
This is the code.
Protected Overrides Sub CreateChildControls()
'Create the GridView
Controls.Clear()
grdTree = New GridView
grdTree.AutoGenerateColumns = True
grdTree.EmptyDataText = "There is no data today"
grdTree.ID = "gvTree"
grdTree.Attributes.Add("runat", "server")
grdTree.Width = 100%
'Try the TemplateField field is created and the header Text is OK
'but there is no DropDownList box in the field.
Dim grdTF As New TemplateField
grdTF.HeaderText = "Checkbox Template Field"
Dim ddlBox As New DropDownList
ddlBox.ID = "ddltop"
ddlBox.Visible = True
ddlBox.Items.Add("One")
ddlBox.Items.Add("Two")
Dim CT As New Control
CT.Controls.Add(ddlBox)
Dim grdTB As New TemplateBuilder
grdTF.ItemTemplate = grdTB
grdTF.ItemTemplate.InstantiateIn(CT)
grdTree.Columns.Add(grdTF)
'CommandField works OK.
Dim grdCF As CommandField = New CommandField
grdCF.ShowSelectButton = True
grdTree.Columns.Add(grdCF)
'BoundField works OK.
Dim grdBF As BoundField = New BoundField
grdBF.DataField = "ProductID"
grdTree.Columns.Add(grdBF)
Dim productTable As New DataTable()
Dim dad As New SqlDataAdapter(selectString, _
connectionString)
dad.Fill(productTable)
grdTree.DataSource = productTable
grdTree.DataBind()
Me.Controls.Add(grdTree)
End Sub
Thank you,