Microsoft has tons of info on this stuff, maybe start here: http://msdn.microsoft.com/asp.net/us...s/default.aspx.
Here's an example of a custom control states drop down list:
StateDropDownList.vb:
VB Code:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace CustomControls
Public Class StateDropDownList : Inherits DropDownList
Public Sub New()
Me.DataBind()
End Sub
Public Overrides Sub DataBind()
MyBase.DataSource = Me.getData()
MyBase.DataTextField = "StateName"
MyBase.DataValueField = "StateCode"
MyBase.DataBind()
End Sub
Private Function getData() As DataTable
Dim dtStates As DataTable
If Not HttpContext.Current Is Nothing _
And Not HttpContext.Current.Cache.Item("StateList") Is Nothing Then
dtStates = CType(HttpContext.Current.Cache.Item("StateList"), DataTable)
Else
Dim cmdText As String = "Select StateName, StateCode From State"
Dim connString As String = "user id=sa;password=sa;database=scratch;server=DeathAngel;"
Dim cn As New SqlConnection(connString)
Dim da As New SqlDataAdapter(cmdText, cn)
dtStates = New DataTable
da.Fill(dtStates)
HttpContext.Current.Cache.Item("StateList") = dtStates
End If
Return dtStates
End Function
End Class
End Namespace
...and the aspx page StateDropDownListTest.aspx:
Code:
<%@ Register TagPrefix="pvb" Assembly="DeathAngel" Namespace="DeathAngel.CustomControls" %>
<html>
<body>
<form runat="server">
<pvb:StateDropDownList Runat="server"/>
</form>
</body>
</html>