S
SAL
Hi,
I am developing a composit control (inheriting from that class) that uses
another class that inherits from ListBox.
My composite control has a value called GridViewID which takes the id of a
GridView and if it is not null, takes the columns and lists them in the
listbox so the user can select which columns to export (to a CSV file for
Excel).
When my composit control load, it's executing the code that adds the items
to the listbox but the items are not showing up on the page that hosts the
composite control. It's probably something very simple but I can't seem to
make the items display in the listbox.
P.S. there's not much error checking in the code yet as I'm just trying to
get the items in the list to display at this point. Any help is much
appreciated.
Here's my CreateChildControls override:
Protected Overrides Sub CreateChildControls()
Controls.Clear()
list = New ExportColumnsList
list.ID = "lstExport"
list.GridviewID = Me.GridviewID
list.ContainerPanelID = Me.ContainerPanelID
btnSubmit = New Button()
btnSubmit.ID = "btnSubmit"
btnSubmit.Text = ButtonText
AddHandler btnSubmit.Click, AddressOf btnSubmit_Click
Me.Controls.Add(list)
Me.Controls.Add(btnSubmit)
End Sub
Protected Overrides Sub RecreateChildControls()
EnsureChildControls()
End Sub
Private Sub ColumnExportTool_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.PreRender
LoadList()
End Sub
Protected Sub LoadList()
If ContainerPanelID <> String.Empty Then
If GridviewID <> String.Empty Then
list.GetGVInContainer(GridviewID, ContainerPanelID)
End If
ElseIf GridviewID <> String.Empty Then
list.GetGVColumns(GridviewID)
End If
End Sub
From the ExportColumnList class:
Protected Friend Sub GetGVColumns(ByVal id As String)
Dim gv As GridView = Page.FindControl(id)
GetColumns(gv)
End Sub
Protected Friend Sub GetGVInContainer(ByVal gridId As String, ByVal panelId
As String)
Dim gv As GridView = Nothing
Dim ctl As Control = Page.FindControl(panelId)
If Not ctl Is Nothing Then
gv = ctl.FindControl(gridId)
GetColumns(gv)
End If
End Sub
Private Sub GetColumns(ByVal gv As GridView)
Dim li As ListItem
If Not gv Is Nothing Then
Dim dcfc As DataControlFieldCollection
dcfc = gv.Columns
For Each dcf As DataControlField In dcfc
If dcf.Visible Then
li = New ListItem
li.Text = dcf.HeaderText
li.Value = dcf.SortExpression
Items.Add(li)
End If
Next
End If
End Sub
S
I am developing a composit control (inheriting from that class) that uses
another class that inherits from ListBox.
My composite control has a value called GridViewID which takes the id of a
GridView and if it is not null, takes the columns and lists them in the
listbox so the user can select which columns to export (to a CSV file for
Excel).
When my composit control load, it's executing the code that adds the items
to the listbox but the items are not showing up on the page that hosts the
composite control. It's probably something very simple but I can't seem to
make the items display in the listbox.
P.S. there's not much error checking in the code yet as I'm just trying to
get the items in the list to display at this point. Any help is much
appreciated.
Here's my CreateChildControls override:
Protected Overrides Sub CreateChildControls()
Controls.Clear()
list = New ExportColumnsList
list.ID = "lstExport"
list.GridviewID = Me.GridviewID
list.ContainerPanelID = Me.ContainerPanelID
btnSubmit = New Button()
btnSubmit.ID = "btnSubmit"
btnSubmit.Text = ButtonText
AddHandler btnSubmit.Click, AddressOf btnSubmit_Click
Me.Controls.Add(list)
Me.Controls.Add(btnSubmit)
End Sub
Protected Overrides Sub RecreateChildControls()
EnsureChildControls()
End Sub
Private Sub ColumnExportTool_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.PreRender
LoadList()
End Sub
Protected Sub LoadList()
If ContainerPanelID <> String.Empty Then
If GridviewID <> String.Empty Then
list.GetGVInContainer(GridviewID, ContainerPanelID)
End If
ElseIf GridviewID <> String.Empty Then
list.GetGVColumns(GridviewID)
End If
End Sub
From the ExportColumnList class:
Protected Friend Sub GetGVColumns(ByVal id As String)
Dim gv As GridView = Page.FindControl(id)
GetColumns(gv)
End Sub
Protected Friend Sub GetGVInContainer(ByVal gridId As String, ByVal panelId
As String)
Dim gv As GridView = Nothing
Dim ctl As Control = Page.FindControl(panelId)
If Not ctl Is Nothing Then
gv = ctl.FindControl(gridId)
GetColumns(gv)
End If
End Sub
Private Sub GetColumns(ByVal gv As GridView)
Dim li As ListItem
If Not gv Is Nothing Then
Dim dcfc As DataControlFieldCollection
dcfc = gv.Columns
For Each dcf As DataControlField In dcfc
If dcf.Visible Then
li = New ListItem
li.Text = dcf.HeaderText
li.Value = dcf.SortExpression
Items.Add(li)
End If
Next
End If
End Sub
S