如何访问类声明的公共变量到ASPX页面? [英] How to access the class declared public variable to ASPX page?

查看:84
本文介绍了如何访问类声明的公共变量到ASPX页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net上有一个小项目。我用了一堂课阅读&访问数据是常见的。现在我不知道如何在aspx页面中使用它。我也可以在aspx.cs中使用它没问题。但aspx页面我无法访问变量。请指教,谢谢



I have a small project in asp.net. I used a class to read & access the data as common. Now I don't know how to use it in aspx page. Also I can use it in aspx.cs no problem. But aspx page I cannot access the variable. Kindly advice me, thanks

MyDataToHold.cs
===============

public class My_GlobalData
    {
        public static System.Data.DataTable MyAddressTbl = new DataTable();
    }

In aspx.cs Page
System.Data.DataTable MyAdrsTbl = MyGlobalData.MyAddressTbl; // Working Good

But in aspx Page
System.Data.DataTable MyAdrsTbl = <%= My_GlobalData.MyAddressTbl %>;// ?????Not Working



再次感谢



我尝试过:



访问aspx页面中的类声明的公共变量


Thanks Again

What I have tried:

Access the class declared public variable in aspx page

推荐答案

试试这个



声明aspx.cs文件中的变量

try this

declare the variable in aspx.cs file
public partial class WebForm1 : System.Web.UI.Page
 {
     public System.Data.DataTable MyAdrsTbl;



并将值赋给变量


and assign the value to the variable

<%=  MyAdrsTbl =  My_GlobalData.MyAddressTbl %>;


这篇关于如何访问类声明的公共变量到ASPX页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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