Konrad Hammerer said:
The 4Guys article describes all that...
hmmm, maybe I have missed something there... I will read it again!
My code (+ explanation):
1)
fillFilters(): fills a combobox with some values
2)
If the user changes the value of the combobox
(cboFilters_SelectedIndexChanged), paintTextBoxes() will add dynamically
rows, cells and textboxes within the cells to a table (added not by code
but with the designer). The Textboxes are filled with default values
which should be changed by the user!
3)
After entering the values, the user clicks a button
(btnExecuteFilter_Click). After this, the function executeFilter()
should read the values but I cannot find/read the controls (rows, cells
and textboxes) -> That is the problem!!!
Code:
Partial Class filter
Inherits System.Web.UI.Page
Private m_cDefaultLVString As String = "(Parameterwert)"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Session.Item("User") = "" Or Session.Item("Password") = "" Then
Session.Add("LastError", "Es sind keine Anmeldedaten im System
hinterlegt!")
Response.Redirect("./showerror.aspx")
End If
If Not Me.IsPostBack Then
'
' get filters from database
'
fillFilters()
End If
lblError.Text = ""
End Sub
Private Sub fillFilters()
Dim oCol As Collection = Nothing
brlvDBHandler.getFilters(Session.Item("User"),
Session.Item("Password"), oCol)
For Each oFilter As brlvFilter In oCol
cboFilters.Items.Add(oFilter.ToString())
Next
If oCol.Count > 0 Then paintTextBoxes(CType(oCol.Item(1), brlvFilter))
End Sub
Protected Sub cboFilters_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles cboFilters.SelectedIndexChanged
Dim oCol As Collection = Nothing
brlvDBHandler.getFilters(Session.Item("User"),
Session.Item("Password"), oCol)
For Each oFiler As brlvFilter In oCol
If cboFilters.SelectedItem.Text = oFiler.ToString Then
paintTextBoxes(oFiler)
End If
Next
End Sub
Private Sub paintTextBoxes(ByVal oFilter As brlvFilter)
Dim txt As TextBox
Dim oFilterParam As brlvFilterParam
Dim oRow As TableRow
Dim oCell1 As TableCell
Dim oCell2 As TableCell
Dim oCell3 As TableCell
oRow = New TableRow
oCell1 = New TableCell
oCell2 = New TableCell
oCell3 = New TableCell
For Each oFilterParam In oFilter.Params
'
' create and fill new textbox
'
txt = New TextBox
If oFilterParam.Name = "Bezirksverband" And oFilterParam.Type =
"Text" Then
txt.Text = Session.Item("Bezirksverband")
Else
txt.Text = m_cDefaultLVString
End If
oRow = New TableRow
oCell1 = New TableCell
oCell2 = New TableCell
oCell3 = New TableCell
oCell1.Text = oFilterParam.Name
oCell1.CssClass = "filter"
oCell2.Controls.Add(txt)
oCell2.CssClass = "filter"
oCell3.Text = "Parameter-Typ: " & oFilterParam.Type
oRow.Cells.Add(oCell1)
oRow.Cells.Add(oCell2)
oRow.Cells.Add(oCell3)
tblParams.Rows.Add(oRow)
Next
End Sub
Protected Sub btnExecuteFilter_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles btnExecuteFilter.Click
Dim oCol As Collection = Nothing
brlvDBHandler.getFilters(Session.Item("User"),
Session.Item("Password"), oCol)
For Each oFilter As brlvFilter In oCol
If cboFilters.SelectedItem.Text = oFilter.ToString Then
paintTextBoxes(oFilter) ' geht so nicht, da sonst alle
User-Angaben wieder überschrieben werden! Und es ist auch irgendwie
unsinnig!
executeFilter(oFilter)
End If
Next
End Sub
Private Sub executeFilter(ByVal oFilter As brlvFilter)
Dim txt As TextBox
lblError.Text = ""
For Each oRow As TableRow In tblParams.Rows
txt = CType(oRow.Cells.Item(1).Controls.Item(0), TextBox)
If txt.Text = m_cDefaultLVString Then
lblError.Text = "Bitte geben Sie für den Parameter """ &
oRow.Cells.Item(0).Text & """ einen gültigen Wert an!"
Return
End If
Next
oFilter.SqlParams.Clear()
End Sub
End Class