Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,This is my code in asp.net
C#
private DataTable CreateDataTable()
   {
       myDataTable = new DataTable("PRODUCTTABLE");

       //DataColumn myDataColumn;

       myDataTable.Columns.Add("Product".ToString());
       myDataTable.Columns.Add("Price".ToString());
       myDataTable.Columns.Add("Quantity".ToString());
       myDataTable.Columns.Add("Total".ToString());
      // myDataTable.Rows.Add(drow);
       ViewState["PRODUCTTABLE"] = myDataTable;
       return myDataTable;
   }


C#
private void Filldatatable()
    {
        myDataTable = (DataTable)ViewState["PRODUCTTABLE"];
        drow = myDataTable.NewRow();
        drow["Product"] = DropDownList1.SelectedItem.Text;
        drow["Price"] = TextBox4.Text;
        drow["Quantity"] = TextBox5.Text;
        drow["Total"] = TextBox6.Text;
        myDataTable.Rows.Add(drow);
        GridView1.DataSource = myDataTable;
        GridView1.DataBind();


    }

now i want to write the same code in window application
but there i am not finding viewstate.so how can i do so.. in window.
what should i do now .please help
Posted

You need to read-learn on the basics of Winform application development.

Or atleast, should understand/notice the difference between the two based on your ASP.NET knowledge. If you know, in ASP.NET there is this concept of postback, client-server request-response thing... and thus various state management techniques.

Viewstate is one of the state management technique to persist the values for the page across postbacks. Now, there is no concept of postbacks in Winforms. Thus, no need of anything like Viewstate.

What do you say, did I put you on some direction that looks helpful?
 
Share this answer
 
Comments
software_Engi08 7-Mar-11 13:43pm    
yes give me some direction.how can i do this
Sandeep Mewara 7-Mar-11 13:50pm    
:doh:... I thought I already gave!
Sergey Alexandrovich Kryukov 7-Mar-11 13:52pm    
Yes you did not bad, my 5.
--SA
Sergey Alexandrovich Kryukov 7-Mar-11 13:52pm    
Will you please see my Answer?
As to general development technology, I would start from MSDN overviews for WPF and/or System.Windows.Forms. By the way, I would recommend skipping Forms and going right to WPF. I worked with my young colleagues who never heard of Forms, started with WPF, very successfully.
Also, MVVM is oriented to WPF; and you can find many good works and code samples; please, again, see my Answer.
--SA
Sandeep Mewara 7-Mar-11 13:55pm    
I would recommend skipping Forms and going right to WPF.
If thats in our hand! :)

you can find many good works and code samples; please, again, see my Answer
Done! and bookmarked too. :)
There is no such concept for desktop application. View state in ASP.NET is related to the fact that HTTP protocol is stateless; and that needs working around for rich Web application. A desktop a application support all states permanently be the obvious reasons, so such concept is not applicable.

Nevertheless, at the architectural level of the desktop application the problem is maintaining coherency between UI states and the data (roughly speaking). There is a number of architectural design patterns (http://en.wikipedia.org/wiki/Architectural_pattern[^]) which help to support the state coherence (in particular): MVVM (http://en.wikipedia.org/wiki/MVVM[^]), Model-View-Controller (http://en.wikipedia.org/wiki/Model_View_Controller[^]) and its derivative Model-view-presenter (http://en.wikipedia.org/wiki/Model-view-presenter[^]).

Perhaps MVVM is the most popular architectural pattern for .NET.

To get a pretty good idea on MVVM, look, for example, here:
Model-View-ViewModel (MVVM) Explained[^],
WPF: MVVM (Model View View-Model) Simplified[^],
MVVM in WPF Part II[^].

Seach CodeProject for more information: there is a lot of interesting articles.

—SA
 
Share this answer
 
v2
Comments
Sandeep Mewara 7-Mar-11 13:54pm    
5! for MVVM details and knowledge base.
Sergey Alexandrovich Kryukov 7-Mar-11 13:55pm    
Thank you, Sandeep.
--SA

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