如何在3层架构师的Web应用程序中使用类库中的viewstate? [英] how to use viewstate in class library in a web application in 3 tier architect?

查看:67
本文介绍了如何在3层架构师的Web应用程序中使用类库中的viewstate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有一个默认页面的应用程序,其中我添加了一个项目2类库(业务层,所有逻辑都在这里),(数据aceess层sql连接)。现在我做了我做了三个文本框来添加值三行和simplying添加在数据表中,填充了3行。现在我使用了viewstate,以便保留以前的值。这项工作是在ui代码上实现的,但现在我在类库(业务层)中添加了一个类queries .cs ..i在cal.cs中使用了datatable ..但是在这里我无法使用viewstate。我知道viewstate是页面控件。如何在类库中使用它。

I have created one application with one default page in which i added a project 2 class library (Business layer,all logics are here),(data aceess layer sql connection).Now wat i did i took three textboxes for adding values thrice and simplying added in datatable with 3 rows filled.now i took viewstate so that value should be retained of previous .this work is achieved on ui code but here now i added one class " queries .cs" in class library (business layer)..i took datatable in cal.cs ..but here i am not able to use viewstate .i know viewstate is page control .how to make it use in class library .

namespace BusinessLayer
{
    public class queries 
    {
        DataTable dt;
        DataRow dr;
       public void createDataTable()
        {
            dt = new DataTable();



            dt.Columns.Add(new DataColumn("Sr.No", typeof(int)));
            dt.Columns.Add(new DataColumn("Product ID", typeof(int)));
            dt.Columns.Add(new DataColumn("Product Name", typeof(string)));
            dt.Columns.Add(new DataColumn("Price", typeof(int)));
            dt.Columns.Add(new DataColumn("Quantity", typeof(int)));
            dt.Columns.Add(new DataColumn("Subtotal", typeof(int)));
            dt.Columns["Sr.No"].AutoIncrement = true;
            dt.Columns["Sr.No"].AutoIncrementSeed = 1;
            dt.Columns["Sr.No"].AutoIncrementStep = 1;
            ViewState["dt"] = dt;

        }





错误 viewstate在当前上下文中不存在



error viewstate does not exist in current context

推荐答案

Hi
try this




Hi,

Try this

namespace BusinessLayer
{
    public class queries 
    {
        DataTable dt;
        DataRow dr;
       public void createDataTable()
        {
            dt = new DataTable();
 

 
            dt.Columns.Add(new DataColumn("Sr.No", typeof(int)));
            dt.Columns.Add(new DataColumn("Product ID", typeof(int)));
            dt.Columns.Add(new DataColumn("Product Name", typeof(string)));
            dt.Columns.Add(new DataColumn("Price", typeof(int)));
            dt.Columns.Add(new DataColumn("Quantity", typeof(int)));
            dt.Columns.Add(new DataColumn("Subtotal", typeof(int)));
            dt.Columns["Sr.No"].AutoIncrement = true;
            dt.Columns["Sr.No"].AutoIncrementSeed = 1;
            dt.Columns["Sr.No"].AutoIncrementStep = 1;
            ViewBag["dt"] = dt;
 
        }


这篇关于如何在3层架构师的Web应用程序中使用类库中的viewstate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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