无法从aspx.cs访问新添加的类 [英] unable to access a newly added class from aspx.cs

查看:86
本文介绍了无法从aspx.cs访问新添加的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- 我有default.aspx页面...我已经添加了一个类

- 在default.aspx.cs的代码后面我试图访问新添加的类。但我无法做到这一点



-----------------------新增课程(不在app_code中)------------------------

  using  System.Configuration; 
使用 System.IO;
使用 System.Data;
使用 System.Data.SqlClient;

///< summary>
///摘要说明 for EmployeeAccessLayer
/// < / < span class =code-leadattribute>摘要 >

public class EmployeeAccessLayer
{
public 员工
{

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


}





-------- -------------------------------在default.aspx.cs中------------- ------



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 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 // 当我尝试访问该课程时,我无法这样做......

}

}







- Gridcustom.DataSource = EmployeeAccessLayer //当我尝试访问该课程时,我无法做到这一点...



请帮助

解决方案

只需右键单击解决方案并添加新项目,弹出一个新窗口添加新项目然后选择Windows,您可以看到中心窗口有很多选项,选择一个类库然后单击确定。

新项目将添加到解决方案中。你可以看到四个选项,如classLibrary1,Properties,Reference和你的类Name1。在你想要的类中添加你的数据和构建这个项目,简单地复制DLL路径,如果你不能获得DLL路径只是Go View Option并选择输出。我希望输出显示。再次构建你的项目输出显示这种类型的路径,这是你的不同路径



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





复制此路径并添加参考项目,你可以用Class。我知道我的英语最差,但我最好。点击回复了解更多信息



Happy Cooding☺


我认为你在Main项目中创建了新的项目类。这个类可以在NameSpace名称的帮助下调用aspx页面(如下面的Myclass)。

 使用系统配置; 
使用 System.IO;
使用 System.Data;
使用 System.Data.SqlClient;

NameSpace myclass
{
public class EmployeeAccessLayer
{
public class 员工
{

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


}

}





Aspx页面中的类调用

 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 myclass;


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

EmployeeAccessLayer emp = New EmployeeAccessLayer();类调用
protected void Page_Load( object sender,EventArgs e)
{

emp.Employee();
if (!IsPostBack)
{

int totalrows = 0 ;

Gridcustom.DataSource = EmployeeAccessLayer // 当我尝试访问该课程时,我无法这样做......

}

}


实例化或使 静态 


-- 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)------------------------

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-------------------

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

解决方案

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

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 ☺


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).

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

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...

        }
 
    }


instantiate the class or make the class static


这篇关于无法从aspx.cs访问新添加的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆