Last post Nov 08, 2010 07:34 AM by toas1
Nov 07, 2010 11:24 PM|dirkjan75|LINK
I have read many post obout n-layer programming, but still have found no good example or reply on some fundamental issues that I have.
I use 3 tier (Dal, BLL, Pll) and for some gridview I want to present the following in one column:
a field 'year' and the fields period 1, period 2, period 3, period 4 and period 5 (all boolean) but only is the value is true. I retrieve all data from a (ms Sql) database. The following code I added to the aspx-file, to create a string that will give me
only the periods that are true (it works):
Public Function perioden(ByVal rst As SVS.POsRow) As String
Dim p As String = ":"
If rst.per1 Then p += "1"
If rst.per2 Then p += " 2"
If rst.per3 Then p += " 3"
If rst.per4 Then p += " 4"
If rst.per5 Then p += " 5"
If p.Length > 3 Then
p = p.Replace(" ", " - ")
In my gridview I added a label (in itemtemplate ) with the following code:
perioden(ctype(ctype(container.dataitem, system.data.datarowview).row, svs.posrow)) %>">
This also works fine. But, now I want to call this function 'perioden' not only in this aspx-file but in my whole webapplication. I tried to create a class with this public function , I get an error that the function isn't found.
So, do I put all this kind of presentation layout code in the aspxfiles (PLL) or cal I somehow more this to a class that can be accessed from all pages?
Nov 08, 2010 01:57 AM|toas1|LINK
if you just add a reference to the assambly that contains your class and imports the namespace where its located there shouldnt be any problems placing this method in another class. If you want to access it the way you do here make it a static method (if
possible) and you then access it using the type rather then an instance.
Nov 08, 2010 05:03 AM|dirkjan75|LINK
I know what you mean but have no idea how to program this. An example that does just this, would be greatly appreciated.
Nov 08, 2010 07:34 AM|toas1|LINK
Either you create a new Class Library project and put your new class in it or you create a class file in you "App_Code" directory in the web application. if you choose the class library path build it and add a reference to it from your application. Next
you import the namespace in your aspx file (following two parts are the same for both solutions):
<%= MyCoolClass.TheStaticMethod() %>
info on creating a class library:
usefull page directive info (including Import):
Hope it helps