Loading ...

Not able to link presentation layer to Code file RSS

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  getting started / general asp.net   » Not able to link presentation layer to Code file RSS

Not able to link presentation layer to Code file RSS

Posts under the topic: Not able to link presentation layer to Code file RSS

Posted: 7/1/2011

Lurker 10  points  Lurker
  • Joined on: 7/1/2011
  • Posts: 2

Hi folks,

I am very new to asp .net and i really need your help.

 I am implementing only dataSet in the data access layer to get the Data from the database.I am not using any dataobjects. when the page loads i need to display the dataset based on the USERID. But i am not able to link presentation layer with the code file.

Below is my code:

 

Data Access Layer:

public class SHTemplateDA:Base.SQLDatabase
{
public DataSet GetSHTemplateListByUserDA(string strUserID)
{
SqlCommand objSqlCommand = Execute.GetCommandObject();
objSqlCommand.CommandText = "SHR_Select_TemplateListByUser";//Stored procedure name
objSqlCommand.Parameters.AddWithValue("@USER_ID", strUserID);
objSqlCommand.CommandType = CommandType.StoredProcedure;
return Execute.ExecuteDataset(objSqlCommand);
}
}
Business Access Layer:
 public class SHTemplateBA : DataAccess.SHTemplateDA
{
public DataSet GetSHTemplateListByUserBA(string strUserID)
{
return GetSHTemplateListByUserDA(strUserID);
}

}
Presentation Layer:
public class SHTemplateUI
{
public DataSet GetSHTemplateListByUserUI(string strUserID)
{
return new SHTemplateBA().GetSHTemplateListByUserBA(strUserID);
}

}
Now what should i write in the code file(.aspx.cs) in order to populate the dataset based on the userID on page load??
Please reply with code guys.


many Thanks,
Arun


Posted: 7/1/2011

Starter 727  points  Starter
  • Joined on: 6/6/2011
  • Posts: 74

Hi Arun,

First you sould transform your DataSet to DataTable, you can do this at your data level or at your presentation level, my recomendation is to do this on your data level. You should return DataTable instead of DataSet in all your levels. Here is the code snippet:

 

public DataTable GetSHTemplateListByUserDA(string strUserID)
{
	SqlCommand objSqlCommand = Execute.GetCommandObject();
	objSqlCommand.CommandText = "SHR_Select_TemplateListByUser";//Stored procedure name
	objSqlCommand.Parameters.AddWithValue("@USER_ID", strUserID);
	objSqlCommand.CommandType = CommandType.StoredProcedure;
	SqlDataAdapter sa = new SqlDataAdapter(objSqlCommand);
	DataSet ds = new DataSet();
	sa.Fill(ds);
	// Convert DataSet to DataTable by getting DataTable at first zero-based index of DataTableCollection
	DataTable dt = ds.Tables[0];
	return dt;
}

public DataTable GetSHTemplateListByUserBA(string strUserID)
{
	return GetSHTemplateListByUserDA(strUserID);
}

public DataTable GetSHTemplateListByUserUI(string strUserID)
{
	return new SHTemplateBA().GetSHTemplateListByUserBA(strUserID);
}

 

In your presentation level depends of what you would/should populate the code is marely the same. Use DataSource = DataTable, and then DataBind(), but the most important thing is when you should/would like to populate the controll, on Page_Load or on button event, i'm giving you code snippet for both of then:

 

protected void Page_Load(object sender, EventArgs e)
{
	if (!IsPostBack)
	{
		// Get the user id
		string userId = "1";
		myGridView.DataSource = GetSHTemplateListByUserUI(userId);
		myGridView.DataBind();
	}
}

protected void btnView_Click(object sender, EventArgs e)
{
	// Get the user id
	string userId = "1";
	myGridView.DataSource = GetSHTemplateListByUserUI(userId);
	myGridView.DataBind();
}




// My .aspx page for displaying result

<asp:GridView ID="myGridView" Runat="server" 
	AutoGenerateColumns="Trye" Pagesize="15" 
	AllowSorting="True" BorderWidth="2px" BackColor="White" 
	GridLines="None" CellPadding="3" Width="100%"
	CellSpacing="1" BorderStyle="Ridge" BorderColor="White"
	AllowPaging="True"  Emptydatatext="No data available." >
	<FooterStyle ForeColor="Black" 
	   BackColor="#C6C3C6"></FooterStyle>
	<PagerStyle ForeColor="Black" HorizontalAlign="Right" 
	   BackColor="#C6C3C6"></PagerStyle>
	<HeaderStyle ForeColor="#E7E7FF" Font-Bold="True" 
	   BackColor="#4A3C8C"></HeaderStyle>
	<SelectedRowStyle ForeColor="White" Font-Bold="True" 
		 BackColor="#9471DE"></SelectedRowStyle>
	<RowStyle ForeColor="Black" BackColor="#DEDFDE"></RowStyle>
</asp:GridView>


You can refer to this tutorial for more deatails: http://msdn.microsoft.com/en-us/library/aa479347.aspx

 

Best Regards,

Gjorgji


Page 1 of 1 (2 items)