Results 1 to 3 of 3

Thread: Can you run code from a module to add items to an aspx page?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Can you run code from a module to add items to an aspx page?

    I have a combo box that I want on all my web pages. Is it possible to run a function from a module and add items to a dropdown box from the module?

    I suppose the best way to do it would be to create a custom combo box and have that load the correct data for the page that it is on. Can someone point me to a good link on creating your own custom objects?

    Thanks
    David Wilhelm

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    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:
    1. Imports System
    2. Imports System.Data
    3. Imports System.Data.SqlClient
    4. Imports System.Web
    5. Imports System.Web.UI
    6. Imports System.Web.UI.WebControls
    7.  
    8. Namespace CustomControls
    9.     Public Class StateDropDownList : Inherits DropDownList
    10.         Public Sub New()
    11.             Me.DataBind()
    12.         End Sub
    13.         Public Overrides Sub DataBind()
    14.             MyBase.DataSource = Me.getData()
    15.             MyBase.DataTextField = "StateName"
    16.             MyBase.DataValueField = "StateCode"
    17.             MyBase.DataBind()
    18.         End Sub
    19.         Private Function getData() As DataTable
    20.             Dim dtStates As DataTable
    21.             If Not HttpContext.Current Is Nothing _
    22.                 And Not HttpContext.Current.Cache.Item("StateList") Is Nothing Then
    23.                 dtStates = CType(HttpContext.Current.Cache.Item("StateList"), DataTable)
    24.             Else
    25.                 Dim cmdText As String = "Select StateName, StateCode From State"
    26.                 Dim connString As String = "user id=sa;password=sa;database=scratch;server=DeathAngel;"
    27.                 Dim cn As New SqlConnection(connString)
    28.                 Dim da As New SqlDataAdapter(cmdText, cn)
    29.                 dtStates = New DataTable
    30.                 da.Fill(dtStates)
    31.                 HttpContext.Current.Cache.Item("StateList") = dtStates
    32.             End If
    33.             Return dtStates
    34.         End Function
    35.  
    36.     End Class
    37. 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>

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612
    pvb, I read some of those but I couldn't quite follow it. Could you look at this and give me a hand please?

    http://www.vbforums.com/showthread.p...hreadid=270076

    Thanks
    David Wilhelm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width