Groups | Blog | Home
all groups > asp.net building controls > february 2005 >

asp.net building controls : Question about Custom Controls


Elmer Carías
2/22/2005 12:09:20 PM
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: elmer_carias@hotmail.com

[quoted text, click to view]

GMK
2/22/2005 1:08:53 PM
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.

AddThis Social Bookmark Button