Last post Oct 22, 2010 01:45 PM by aderegil
Oct 21, 2010 11:54 AM|Carlitta87|LINK
Im trying to utilize this way of programming. This is my first time doing it this way and I unfortunately cant seem to find the answer online. Is there anyone who might know, how can i bind information to my controls(theses are text-boxes and drop down menu)
while I am using a strongly typed dataset (BLL and DAL). I really would appreciate the help. Thank You
DAL & BLL classes
Oct 21, 2010 01:28 PM|aderegil|LINK
Please tell us a little bit more about your project.
- It is a ASP.Net WebForms project?
- Can you share with us some sample BLL class that you want to bind to a textbox/ddl?
It is not complicated, but we just need some extra info to give you accurate suggestions!
Oct 21, 2010 01:43 PM|riswadkarharshad|LINK
As Alfredo said, it would be helpful if you can share more details about your project. As per my understanding, you are trying to implement 3 tier architecture in your asp.net application. You can do the following;
Add reference of BLL in asp.net application and call relevant methods for select/insert/update/delete.
Add reference of DAL in BLL and pass the data coming from asp.net to DAL. You can also add your application related logic in BLL.
The DAL should be the one that directly communicates with the DB and return the result of the operation.
I hope this helps.
Oct 21, 2010 01:50 PM|Carlitta87|LINK
Well, for the DAL I used datasets and create 3 procedures getdata, getdatabyid, updatesetupby id.
and in the BLL
Public Class SetupBLL
Private _setupAdapter As SetupTableAdapter = Nothing
Protected ReadOnly Property Adapter() As SetupTableAdapter
If _setupAdapter Is Nothing Then
_setupAdapter = New SetupTableAdapter()
<System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, True)> _
Public Function GetProducts() As Setup.SetupDataTable
<System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, False)> _
Public Function GetDataByID(ByVal CompanyNo As Integer) As Setup.SetupDataTable
<System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, True)> _
Public Function UpdateSetup(ByVal SchoolName As String, ByVal Address As String, ByVal PhoneNos As String, ByVal FaxNos As String, _
ByVal eMailAddress As String, ByVal WebsiteAddress As String, ByVal Logo As Byte, ByVal CurrentAcademicYearID As Nullable(Of Integer), _
ByVal ChequeNo As Nullable(Of Integer), ByVal ClosingDate As DateTime, ByVal BackgroundImage As Byte, ByVal SchoolType As String, _
ByVal StudentIDPrint As Nullable(Of Integer), ByVal StudentReport As Nullable(Of Integer), ByVal TranscriptReport As Nullable(Of Integer), _
ByVal TRAcademicTerm As Nullable(Of Integer), ByVal Chairman As String, ByVal Principal As String, ByVal Bursar As String, _
ByVal CompanyNo As String) As Boolean
Dim schooldetails As Setup.SetupDataTable = Adapter.GetDataByID(CompanyNo)
If schooldetails.Count = 0 Then
' no matching record found, return false
Dim setup As Setup.SetupRow = schooldetails(0)
setup.SchoolName = SchoolName.ToString
setup.Address = Address.ToString
setup.PhoneNos = PhoneNos.ToString
setup.FaxNos = FaxNos.ToString
setup.eMailAddress = eMailAddress.ToString
setup.WebsiteAddress = WebsiteAddress.ToString
'If Logo Is Nothing Then setup.SetLogoNull() Else setup.Logo = Logo
If Not CurrentAcademicYearID.HasValue Then setup.SetCurrentAcadamicYearIdNull() Else setup.CurrentAcadamicYearId = CurrentAcademicYearID.HasValue
If Not ChequeNo.HasValue Then setup.SetChequeNoNull() Else setup.ChequeNo = ChequeNo.HasValue
setup.ClosingDate = ClosingDate
'If BackgroundImage Is Nothing Then setup.SetLogoNull() Else setup.Logo = BackgroundImage
setup.SchoolType = SchoolType.ToString
If Not StudentIDPrint.HasValue Then setup.SetStudentIDPrintNull() Else setup.StudentIDPrint = StudentIDPrint.HasValue
If Not StudentReport.HasValue Then setup.SetStudentReportNull() Else setup.StudentReport = StudentReport.HasValue
If Not TranscriptReport.HasValue Then setup.SetTranscriptReportNull() Else setup.TranscriptReport = TranscriptReport.HasValue
If Not TRAcademicTerm.HasValue Then setup.SetTRAcademicTermNull() Else setup.TRAcademicTerm = TRAcademicTerm.HasValue
setup.Chairman = Chairman.ToString
setup.Principal = Principal.ToString
setup.Bursar = Bursar.ToString
' Update the product record
Dim rowsAffected As Integer = Adapter.Update(setup)
' Return true if precisely one row was updated, otherwise false
Return rowsAffected = 1
i only did an update because the intention is to display the information and update only.
In my code behind i know how to bind it to a gridview but i am unsure how to bind it to controls on the page such as textboxes, dropdownlist, etc...
I hope this was adequate information.
bll business layer objects
3 tier architecture
Oct 21, 2010 01:56 PM|aderegil|LINK
If you have a collection of objects, like the DataSets that you use, you can "bind" that collection to some ASP.Net controls like GridView, Repeater, DataList, etc.
If you have a single object and you want to "bind" one particular property of that object to some ASP.Net control like TextBox, Label, etc, then you do something like this:
txbSchoolName.Text = setup.SchoolName
You need to choose one Property from your object to "bind" it to one property of your control, usually the Text property. This is not really a binding. There is no binding in the way that you may be thinking. If you later want to READ the value that the
user put on your control you do it the other way:
setup.SchoolName = txbSchoolName.Text
Does this make sense to you?
Oct 21, 2010 03:26 PM|Carlitta87|LINK
txbSchoolName.Text = setup.SchoolName
Do I use this method even though i am using a dataset instead of classes in the DAL?...This method i would have to create private members for each of the columns in my table, correct? This is how it should be done at all times?
Oct 21, 2010 03:29 PM|aderegil|LINK
For this fictional sample, you tell me please, where do you have retrieved the school name from your database?
You mentioned a DataSet?
So you may have it inside the first row of the first table of your DataSet?
txbSchoolName.Text = yourDataSet.Tables.Rows[SchoolName];
Are you following me?
Oct 21, 2010 03:41 PM|Carlitta87|LINK
well i am trying that now actually in my code behind
"school_name_textbox.Text = Setup.Tables(0).Rows(0).SchoolName"
but i get an error: Reference to a non-shared member requires an object reference.
and i assume i'm missing something else.
Oct 21, 2010 03:59 PM|aderegil|LINK
What I am not understanding from your code is where do you actually call your DAL in order to receive the schoolname property? That property is inside an object? It is inside a collection? inside a dataset?
Please help me understand that.
Oct 22, 2010 11:04 AM|Carlitta87|LINK
Public Function GetDataByID(ByVal CompanyNo As Integer) As Setup.SetupRow
If String.IsNullOrEmpty(CompanyNo) Then
Throw New ArgumentNullException(CompanyNo)
Dim adapter As New SetupTableAdapter()
Dim table As New Setup.SetupDataTable()
If table.Rows.Count = 0 Then
Return DirectCast(table.Rows(0), Setup.SetupRow)
and in the behind code...
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Bind to Gridview
Dim SetupAdapter As New SetupTableAdapter
GridView12.DataSource = SetupAdapter.GetDataByID(1234)
'Bind to Control
Dim row As Setup.SetupRow = GetDataByID("1234")
i think this is wat you are asking for?...
Oct 22, 2010 12:52 PM|aderegil|LINK
Hello, yes. So you have your "record of data" on a variable called row of Setup.SetupRow.
I do not see the definition of the Setup.SetupRow class but I believe it has a Schoolname property. So you can try to assign the value of that property to the .Text property of your control.
txbSchoolName.Text = row.Schoolname
Can you try that? Does that make sense to you?
Oct 22, 2010 01:40 PM|Carlitta87|LINK
i see what your saying and i am getting the concept :) theres one thing though. The definition of the Setup Row, i'm not sure where to put it. I'm not sure i should place it in the DAL folder as a class and then this code
Partial Public Class Setup
Partial Public Class SetupRow
Public Function GetData() As SetupDataTable
Dim setupAdapter As New SetupTableAdapters.SetupTableAdapter
am i correct?
Oct 22, 2010 01:45 PM|aderegil|LINK
As I understand your code I think the Setup and SetupRow classes are your business entities that will receive information from your database. You will use them to store that info and then pass it to the user interface layer.
So you can put them wherever you want, if you have a business layer folder you can put them there. As soon as they are available for the whole project.