Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 21st, 2003, 01:00 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default Need help creating reusable code in a class.

Hi all,

   This is what I am trying to do. I am converting an ASP app to ASP.NET. They put their code into an ASP include file. They fill dropdowns etc by calling stored procedures and looping through a recordset and creating an HTML string. They send it back to the calling page to create the dropdown <%=GetPlans()%>
   I want to create the same reusable code in .NET. I created a classfile and put a function into it(there will be many). Here is the code:
Imports System.Data.SqlClient

Public Class TestClass

    Public Function GetPlans()

        Dim dsPlans As New DataSet()
        Dim sqlConn As New SqlConnection()

        sqlConn.ConnectionString = "data source=MOTLEYCRUE;initial catalog=PATII;integrated security=SSPI;persist security info=False;packet size=4096"

        Dim sdaPlans As New SqlClient.SqlDataAdapter("dbo.[CaseManagementGetPlans]", sqlConn)
        sdaPlans.Fill(dsPlans, "Plans")

        Return dsPlans

    End Function

End Class

Here is the code in my aspx page:
Public Class WebForm1
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Dim x As New TestClass()
    Protected WithEvents ddl1 As System.Web.UI.WebControls.DropDownList
    Dim ds As New DataSet()

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        ds = x.GetPlans

        ddl1.DataSource = ds
        ddl1.DataMember = ds.Tables(0).TableName
        ddl1.DataTextField = ds.Tables(0).Columns(1).ColumnName
        ddl1.DataValueField = ds.Tables(0).Columns(0).ColumnName
    End Sub

End Class

The problem is that it runs with no errors, but my drop down list is empty. Am I doing this correctly, is there a better way? Any help and advice would be greatly appreciated.

Thanks

Jim

  #2 (permalink)  
Old November 21st, 2003, 01:07 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I figured it out .. something stupid of course... I got so caught up in the other syntax.. I forgot to databind the drop down list

DUH!!!!!



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Reusable Page Templates workidoo BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 June 25th, 2008 04:58 PM
Need help creating this Form with a backend Class iampedro ASP.NET 2.0 Basics 0 February 10th, 2007 05:26 PM
creating an event for a custom class? lkubler BOOK: Beginning Access 2003 VBA 3 September 20th, 2005 03:47 PM
creating a .dll from a .cs class vb_developer C# 1 October 27th, 2004 05:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.