How do I add a dataset to ViewState

Right now I have this code.

private void BindTextBoxes()
            {
      this.txt_fname.Text=CustomerGridData.Tables["t_customers"].Columns"customer_fname"].ToString();
            }

But I get this error at run time

Object reference not set to an instance of an object.  I think ViewState is the answer but I'm not sure how to add a dataset to ViewState.

Thanks,
Sean
sean-keysAsked:
Who is Participating?
 
RamuncikasCommented:
Hey, Sean.

I know VB.NET better than C# but i think it will be easy to understand:

To store data into ViewState use this:
Me.Viewstate("t_customers")=CustomerGridData.Tables("t_customers")

To retrieve what you have stored use this:
Dim T_Customers as New DataTable
T_Customers=CType(Me.Viewstate("t_customers"), DataTable)

Hope this will help
Good luck
Ramuncikas
0
 
praneethaCommented:
 this.txt_fname.Text=CustomerGridData.Tables["t_customers"].Columns"customer_fname"].ToString();

r u missing [ after Columns
0
 
sean-keysAuthor Commented:
private void BindTextBoxes()
            {
                  this.txt_fname.Text=CustomerGridData.Tables["t_customers"].Columns["customer_fname"].ToString();
            }



That’s the actual code, not the debug output.


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.