Question about Custom Controls

G

GMK

Dear all
I'm building a web application that some standard controls in many pages as
"DropDownlist" this drop down list is filled from a table in a specific
database and this "DropDownlist" will be used in many apges and on each page
the data inside the "DropDownlist" will be the same but the use of this data
will be from different events.
how could i create such a control and if there are any tutorial which would
help me in building this control i would be so thankful.

thank you so much for your help.

GMK.
 
E

Elmer Carías

Look the code i put here, i hope so that code helps you, its an example of
an CustomControl inherits from DropDownList, and when you drag&drop the
control in your page you can see all the events same a normal DropDownList,
but this dropdownlist bind the data automatically,

Imports System.ComponentModel
Imports System.Web.UI

<DefaultProperty("idCuentaContable"), ToolboxData("<{0}:ddlbCuentaContable
runat=server></{0}:ddlbCuentaContable>")> _

Public Class ddlbCuentaContable

Inherits System.Web.UI.WebControls.DropDownList

Private _idCuentaContable As Integer

Private _sError As Boolean

Public Event ErrorEvent As EventHandler

Public ReadOnly Property sError() As String

Get

Return _sError

End Get

End Property

<Bindable(True), Category("Data"), DefaultValue(0)> _

Public Property idCuentaContable() As Integer

Get

Return _idCuentaContable

End Get

Set(ByVal Value As Integer)

_idCuentaContable = Value

If Value > 0 Then

Me.SelectedValue = Me._idCuentaContable

End If

End Set

End Property

Private Sub RecuperarLista()

Dim mWr As New wrCatalogosContabilidad.CatalogosContabilidad

Dim sError As New String("")

Dim dsDatos As DataSet

sError = mWr.ObtenerListaValorCuentasContables(dsDatos)

If Not sError = "" Then

Me._sError = "Error al obtenerListado de Cuenta Contable. " + sError

Dim e As EventArgs

RaiseEvent ErrorEvent(Me, e)

Return

End If

Me.DataSource = dsDatos

Me.DataTextField = "nombreCuenta"

Me.DataValueField = "idCuenta"

Me.DataBind()

End Sub



Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)

Me._idCuentaContable = Me.SelectedValue

MyBase.OnSelectedIndexChanged(e)

End Sub

Protected Overrides Sub OnInit(ByVal e As System.EventArgs)

Me.RecuperarLista()

MyBase.OnInit(e)

End Sub

End Class


Elmer Carías
El Salvador, CA
DCE 3
MSN Messenger: (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top