Click here to Skip to main content
12,954,631 members (54,617 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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 12-Feb-13 23:03pm

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 13-Feb-13 5:50am
   
what is viewbag.and do ineed to add any reference to have viewstate??????????????
Devang Vaja 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
Top Experts
Last 24hrsThis month
OriginalGriff 6,539
CHill60 3,490
Maciej Los 3,153
ppolymorphe 2,030
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2017
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