|
Custom selfpopulating listbox Posted: 24 Jan 2010 01:16 AM |
Hallo,
ik heb een probleem bij een custom control die ik maakte
Doe ik dit in mijn pagina waar ik een formview heb op staan :
<avi:mycoDropDownList ID="GW_Voorzitter" Width="450px" runat="server" whereValue='1' DataValueField="id" DataTextField="naam" SourceTable="l_view" />
dan vult de listbox zich op.
Doe ik echter dit :
<avi:mycoDropDownList ID="GW_Voorzitter" Width="450px" runat="server" whereValue='<%#Eval("Id")%>' DataValueField="id" DataTextField="naam" SourceTable="l_view" />
dan blijft de listbox leeg.
<%Eval(“Id”)%> is nochtans zeker 1 en de control krijgt dit ook zo door... ziet iemand van jullie de fout ?
Wat nog gekker is als ik <%Eval(“Id”)%> laat staan maar de select van mijn customcontrol aanpas naar :
strSelect = "SELECT " & MyBase.DataValueField & ", " & MyBase.DataTextField & " FROM " & m_strSourceTable & " WHERE id_gew=1 ORDER BY naam"
maw de waarde niet gebruik dan blijft de listbox ook leeg ????
Een tweede raar punt is dat ik in mijn control
MyBase.DataTextField = "naam"
MyBase.DataValueField = "id"
moet laten staan hoewel deze property op de pagina wordt ingesteld, doe ik deze weg uit de control dan blijft deze ook leeg ???
Dank voor de moeite om dit eens te bekijken
Filip
Mijn control :
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports MySql.Data.MySqlClient
<DefaultProperty("SourceTable"), ToolboxData("<{0}:mycoDropDownList runat=server></{0}:mycoDropDownList>")> _
Public Class mycoDropDownList
Inherits System.Web.UI.WebControls.DropDownList
Private m_strConnectionString As String
Private m_strSourceTable As String
Private m_strSourceColumn As String
Private m_intWhereValue As Integer
<Bindable(True), Category("Data"), DefaultValue("")> _
Public Property SourceTable() As String
Get
Return m_strSourceTable
End Get
Set(ByVal value As String)
m_strSourceTable = value
End Set
End Property
<Bindable(True), Category("Data"), DefaultValue("")> _
Public Property sourceColumn() As String
Get
Return m_strSourceColumn
End Get
Set(ByVal value As String)
m_strSourceColumn = value
End Set
End Property
<Bindable(True), Category("Data"), DefaultValue(0)> _
Public Property whereValue() As Integer
Get
Return m_intWhereValue
End Get
Set(ByVal value As Integer)
m_intWhereValue = value
End Set
End Property
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
MyBase.OnPreRender(e)
Dim cnn As MySqlConnection = Nothing
Dim cmd As MySqlCommand = Nothing
Dim drData As MySqlDataReader = Nothing
Dim strSelect As String = ""
Dim bResult As Boolean = True
strSelect = "SELECT " & MyBase.DataValueField & ", " & MyBase.DataTextField & " FROM " & m_strSourceTable & " WHERE id_gew=" _
& m_intWhereValue & " ORDER BY naam"
Try
cnn = New MySqlConnection("server=localhost;user id=***;password=***;persist security info=True;database=clubadmin")
cmd = New MySqlCommand()
cmd.CommandText = strSelect
cmd.CommandType = System.Data.CommandType.Text
cnn.Open()
cmd.Connection = cnn
drData = cmd.ExecuteReader()
' bind to the control
MyBase.DataSource = drData
MyBase.DataBind()
MyBase.DataTextField = "naam"
MyBase.DataValueField = "id"
' clean up
drData.Close()
cnn.Close()
Catch ee As Exception
m_strErrorMsg = ee.Message
End Try
End Sub
End Class
|
|
|
 |
|