[thelist] ASP.NET: Populate a datalist from with a class

Casey Crookston caseyc at IntelliSoftmn.com
Wed Aug 9 09:31:17 CDT 2006


Good Morning,

 

I'm trying to implement some of the tips I've learned on this list over
the past few days.  I've got a datalist which is populated with a list
of categories - I'm trying to populate it from a class file. I was
thinking I'd put all calls to the database in this one class file.

 

In the main file's page behind:

 

Public Sub GetCategoryResults(ByVal sender As Object, ByVal e As
System.EventArgs)

 tblReturns.Visible = True

 Dim sqlHelper As New SqlHelperCS

 sqlHelper.returnCategories(sender)

End Sub

 

~~~~~~~Then in the class:~~~~~~~~~~~~~

 

Namespace SqlHelperNS

 Public Class SqlHelperCS

  Protected WithEvents dtlCats As System.Web.UI.WebControls.DataList

  Dim dbConnect As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("dataConnection"))

 

  Sub returnCategories(ByVal catLetter)

     Dim dbCommand As SqlCommand = New SqlCommand("getCategories",
dbConnect)

     dbCommand.CommandType = CommandType.StoredProcedure

     dbCommand.Parameters.Add("@catLetter",
HttpUtility.HtmlDecode(catLetter.ToString.Trim) & "%")

     dbConnect.Open()

     Dim dtrCats As SqlDataReader = dbCommand.ExecuteReader()

     dtlCats.DataSource = dtrCats

     dtlCats.DataBind()

     dbConnect.Close()

  End Sub

End Class

 

End Namespace

~~~~~~~~~~~~~~~~~~~~

 The trouble is, the class will not recognize the datalist.  By doing
this in the class, and I creating more work then I need?

 

Thanks,

 

Casey

 




More information about the thelist mailing list