Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
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;
 
        }
 
error viewstate does not exist in current context
Posted 13-Feb-13 0:03am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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;
 
        }
  Permalink  
Comments
shivani 2013 at 13-Feb-13 5:50am
   
what is viewbag.and do ineed to add any reference to have viewstate??????????????
Devang Vaja at 19-Feb-13 7:41am
   
shivani ji plz read this
https://www.google.co.in/#hl=en&sugexp=les%3B&gs_rn=3&gs_ri=psy-ab&tok=wJtbbmUZgIFcX75_zvBGeQ&cp=9&gs_id=fy&xhr=t&q=viewbag+in+mvc3&es_nrs=true&pf=p&tbo=d&output=search&sclient=psy-ab&oq=viewbag+i&gs_l=&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&bvm=bv.42553238,d.bmk&fp=81d14d7c7e348b8c&biw=1364&bih=638

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

  Print Answers RSS
0 OriginalGriff 190
1 Jochen Arndt 165
2 PIEBALDconsult 150
3 BillWoodruff 148
4 DamithSL 140
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100