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

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Wed Aug 9 13:44:15 CDT 2006


> and (sic) I creating more work then I need?

I'd say so.

Why not just have the class return the data object and then you can bind it to the appropriate control?  It seems silly to encapsulate functionality like this in a class when it pertains to one particular datalist; better to put the datalist itself and the logic in a user control (or a custom control if you want to get fancy, though that hardly seems necessary).

FWIW,

Peter

 From: "Casey Crookston" caseyc at IntelliSoftmn.com

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

-- 

* * Please support the community that supports you. * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester 
and archives of thelist go to: http://lists.evolt.org 
Workers of the Web, evolt ! 





More information about the thelist mailing list