Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 .
C#
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

1 solution

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;
 
        }
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900