Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
-- i have default.aspx page... i have added a class
-- in code behind of default.aspx.cs i am trying to access newly added class. But i am unable to do that

-----------------------Newly Added class(not in app_code)------------------------
VB
using System.Configuration;
using System.IO;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for EmployeeAccessLayer
/// </summary>

public class EmployeeAccessLayer
{
 public class Employee
    {

        public int id { get; set; }
        public string name { get; set; }
        public int age { get; set; }
        public string sex { get; set; }
    }


}


---------------------------------------in default.aspx.cs-------------------

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;



public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {

            int totalrows = 0;

            Gridcustom.DataSource= EmployeeAccessLayer  //when i try to access that class here i am unable to do that...

        }

    }



-- Gridcustom.DataSource= EmployeeAccessLayer //when i try to access that class here i am unable to do that...

kindly help
Posted
Comments
Prasaad SJ 18-Dec-13 3:34am    
I m not sure.. Is this your problem..

R you accessing the Employee directly.. ??
Like

Gridcustom.DataSource= Employee; // You cannot access this way.

You can access only by the following

Gridcustom.DataSource= EmployeeAccessLayer.Employee;
anurag19289 19-Dec-13 6:24am    
no i am was trying to access in this way Gridcustom.DataSource= EmployeeAccessLayer.Employee;
but when i typed EmployeeAccessLayer. I was getting error
anurag19289 19-Dec-13 6:24am    
i am doing in this way.... file-->new website
not file-->new project

just right click on the Solution and add new Project, one New window is pop up "Add New Project"then select Windows and you can see in the center window have many option are there, select a class Library and then click ok.
new project will be add in Solution. you can seen four option like classLibrary1,Properties,Reference and your class Name Class1. Add you data in class as you want and Build this project,simple copy the DLL path, if you can't get a DLL path just Go View Option and select output. I hope output is showing. Build again your project output is showing this type of Path,This is Different path your side

C#
E:\myspce2\c# program\LAB MASTER\myclass\bin\Debug\myclass.dll


copy this path and add in Reference Project, you can used the Class. I know my english is worst but i try best. hit to reply for more information

Happy Cooding ☺
 
Share this answer
 
I think you make the new project class in Main project. this class can call in aspx page with the help of NameSpace Name (like below Myclass).
C#
using System.Configuration;
using System.IO;
using System.Data;
using System.Data.SqlClient;
 
NameSpace myclass
{
public class EmployeeAccessLayer
{
 public class Employee
    {
 
        public int id { get; set; }
        public string name { get; set; }
        public int age { get; set; }
        public string sex { get; set; }
    }
 

}

}


Class call in Aspx page
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using myclass; 

 
public partial class _Default : System.Web.UI.Page
{

EmployeeAccessLayer emp= New EmployeeAccessLayer(); Class call here 
    protected void Page_Load(object sender, EventArgs e)
    {
 
emp.Employee();
        if (!IsPostBack)
        {
 
            int totalrows = 0;
 
            Gridcustom.DataSource= EmployeeAccessLayer  //when i try to access that class here i am unable to do that...

        }
 
    }
 
Share this answer
 
Comments
anurag19289 19-Dec-13 7:24am    
i was doing file-->new website. then its not working
but when i do fiole-->new project. it works. can you clarify this doubt.
joginder-banger 19-Dec-13 9:18am    
send your email id...I send my complete project then after you problem... free feel ask me...
anurag19289 20-Dec-13 10:21am    
Brother my email id

anurag.19289@gmail.com
C#
instantiate the class or make the class static
 
Share this answer
 
Comments
anurag19289 17-Dec-13 13:57pm    
made the class static but not working
anurag19289 17-Dec-13 13:57pm    
public static class EmployeeAccessLayer
{
public class Employee
{

public int id { get; set; }
public string name { get; set; }
public int age { get; set; }
public string sex { get; set; }
}
Create Namespace can define the Scope of the Defined class which gives an organized access.Already , Joginder has pointed out that .

MyNamespace.MyClass

Just wanted to add that instead of EmployeeAccessLayer defined as a parent class can be the namespace if the intention was to group the Employee related classes.So the accessing of nested classes can also be well avoided.Or else you have to take care of the instantiation of the containing classes residing in the parent class.

Hope this helps you...
 
Share this answer
 
Comments
anurag19289 19-Dec-13 7:25am    
I was doing file-->new website. then its not working
but when i do fiole-->new project. it works. can you clarify this doubt.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900