Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do you Programmatically store values in a WebPart?

Posted on 2011-09-08
12
Medium Priority
?
267 Views
Last Modified: 2012-05-12
I need to have a per user DataTable Programmatically stored in a web-part.
0
Comment
Question by:Rahsaan-Pringle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
12 Comments
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 36503522
Session? ViewState?

If you don't want to use the server's memory you can  use a Sql Table where user is part of the table itself.   It allows you to then
select * from table where user = @user

0
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 36503552
From here:
http://msdn.microsoft.com/en-us/library/e0s9t4ck.aspx

I see this:
Creating a Data-Bound Web Parts Control
http://msdn.microsoft.com/en-us/library/ms227438.aspx

And here a code sample from a link on that page:
http://msdn.microsoft.com/en-us/library/ms227548.aspx
0
 

Author Comment

by:Rahsaan-Pringle
ID: 36503613
I originally planned to store the data in the database, because it's tabular in nature (two columns, x rows). I have been directed to avoid using the database. As far as I know, cookies aren't suitable because it's tabular, and Session isn't good because the data needs to persist between sessions. Data-Bounding isn't suitable because I have been told not to use the database.
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 36503623
If data needs to be persisted between sessions than database is definitely the way to go.  Cookies should be able to store that data depending on the number of rows though.  

0
 

Author Comment

by:Rahsaan-Pringle
ID: 36503625
I agree about the database. How do you stick a table in a cookie?
0
 

Author Comment

by:Rahsaan-Pringle
ID: 36503629
I agree about the database. How do you stick a DataTable in a cookie?
0
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 36503671
same way would the session.  Just use create a cookie object.

http://msdn.microsoft.com/en-us/library/78c837bd.aspx#Y239


HttpCookie myCookie = new HttpCookie("UserSettings");
myCookie["Font"] = "Arial";
myCookie["Color"] = "Blue";
myCookie.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(myCookie);


myCookie["Datatable"] = dt;
0
 

Accepted Solution

by:
Rahsaan-Pringle earned 0 total points
ID: 36503711
It's good to know I'm not entirely crazy. I did try that. It says you can't convert DTs to strings.
52E43607-FDE0-4507-9993-B3DAB520.png
0
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 36504527
Would do it the hard way then.

Make a delimited string:

String tmp ="";

for each row in dt.Rows
  tmp += row.Columns[0] + "|" + row.Columns[1] + "|" . . .  "~";

//write to cookie

then on load do spilts:

int i;
for each string tmpRow in  myCookie["dt"].ToString().Split("!")
{
   i = 0;
   DataRow row = dt.NewRow();
   for each string col in tmpRow.Split("|")
   {
     row[ i ] = col;
     i++;
   }
     dt.Rows.Add(row);
}

     
0
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 36504747
Just remember the max cookie size is 4k.
0
 

Author Closing Comment

by:Rahsaan-Pringle
ID: 36898934
I had to try something else.
0
 

Author Comment

by:Rahsaan-Pringle
ID: 36711247
zzz
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question