Solved

Session[keys.Current.ToString()]));

Posted on 2006-11-07
24
519 Views
Last Modified: 2008-01-09
do you think i can change from Session to ViewState?
 
when i do Session[keys.Current.ToString()] then its loading my class and class has 53 public properties

but i dont want to load the class into session keys, is there a way i can change to ViewState or is there a way to have different approach?

protected void dg_PreRender(object sender, EventArgs e)
    {
        IEnumerator keys = Session.Contents.GetEnumerator();
       
        if (Session.Count > 0)
        {
            while (keys.MoveNext())
            {
                string value = Convert.ToString((Session[keys.Current.ToString()]));
                if (value.Substring(0, 1) == dg.MasterTableView.CurrentPageIndex.ToString())
                {
                    foreach (GridDataItem dataItem in dg.MasterTableView.Items)
                    {
                        CheckBox box = (CheckBox)dataItem["TemplateColumn"].FindControl("checkBox1");
                        string clientID = value.Substring(2, (value.Length - 7));
                        if (box.ClientID == clientID)
                        {
                            box.Checked = true;
                        }
                    }
                }
            }
        }
    }
0
Comment
Question by:Islam1424
  • 11
  • 9
24 Comments
 
LVL 8

Expert Comment

by:sabeesh
ID: 17896091
if possible create a class with keys are the the properties and assigin values to this class and set this class as the viewstate.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17897525
You need to be careful what you store in ViewState.  It is carried along with the page in a UTF-16, Base-64 encoded text.  It is meant for light-weight storage, as the page response goes down drastically when more and more things are stored in the ViewState.

Bob
0
 

Author Comment

by:Islam1424
ID: 17898097
i want to modify the above code, is that possible?

what is heppaning is:

its loading my clsUser in the session context and may be this is due to i'm using
((Session[keys.Current.

is there a way to find why is is it loading my class in to session context?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17898156
What are you looking to store in Session variables?

Bob
0
 

Author Comment

by:Islam1424
ID: 17898753
is there a way i can use dictionary instead of session? i haven't use dictionary before so i have not clue how i can replace to it.

actually, i have a data grid with check box so I'm storing how many check box user have checked.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17898797
Sure, you could use Dictionary, but if you need to persist it, then it would need to be stored in the Session.

Bob
0
 

Author Comment

by:Islam1424
ID: 17898914
you mean only session have to use here?, no other way?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17899002
Is your page going to post back?  If not, then you can use the Dictionary without worry.  But, if it does, then you need to store the Dictionary in the Session:

    Session["CheckedList"] = dictionaryChecked;

Bob
0
 

Author Comment

by:Islam1424
ID: 17899066
Thanks Bob

but how do i use dictionary ?, i dont know how to use dictionary

can you show me an example pls.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17899096
Something like this:

using System.Collections.Specialized;

StringDictionary _dictionary = new StringDictionary();

_dictionary.Add(key, value);

Bob
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Islam1424
ID: 17899125
is there a way you can modify my below code to dictionary? please :)


protected void dg_PreRender(object sender, EventArgs e)
    {
        IEnumerator keys = Session.Contents.GetEnumerator();
       
        if (Session.Count > 0)
        {
            while (keys.MoveNext())
            {
                string value = Convert.ToString((Session[keys.Current.ToString()]));
                if (value.Substring(0, 1) == dg.MasterTableView.CurrentPageIndex.ToString())
                {
                    foreach (GridDataItem dataItem in dg.MasterTableView.Items)
                    {
                        CheckBox box = (CheckBox)dataItem["TemplateColumn"].FindControl("checkBox1");
                        string clientID = value.Substring(2, (value.Length - 7));
                        if (box.ClientID == clientID)
                        {
                            box.Checked = true;
                        }
                    }
                }
            }
        }
    }
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17899151
You only need this For block:

                    foreach (GridDataItem dataItem in dg.MasterTableView.Items)
                    {
                        CheckBox box = (CheckBox)dataItem["TemplateColumn"].FindControl("checkBox1");
                        string clientID = value.Substring(2, (value.Length - 7));
                        if (box.ClientID == clientID)
                        {
                            box.Checked = true;
                            _dictionary.Add(clientID, box);
                        }
                    }

Bob
0
 

Author Comment

by:Islam1424
ID: 17899420
Error      1      The name 'value' does not exist in the current context       

      protected void RadGrid1_PreRender(object sender, EventArgs e)
    {      
            foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
            {
                CheckBox box = (CheckBox)dataItem["TemplateColumn"].FindControl("checkBox1");
                string clientID = value.Substring(2, (value.Length-7));                        
                if(box.ClientID==clientID)
                {
                    box.Checked = true;
                    _dictionary.Add(clientID, box);
                }
            }
    }
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17905448
Describe to me with words what this For loop is doing, please.

Bob
0
 

Author Comment

by:Islam1424
ID: 17918354
Bob,

i'm using datagrid with checkboxes so i want to maintain what i have checked even thou the user change the page numbers of datagrid.

thanks.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17922421
What is the DataGrid bound to?

Bob
0
 

Author Comment

by:Islam1424
ID: 17932085
datagrid bound to a DataSet
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17932143
I would suggest adding a column for the check boxes to the DataTable, instead of what you have been trying to do.

Bob
0
 

Author Comment

by:Islam1424
ID: 17932980
can you throw me some sample lines please?

thanks
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 125 total points
ID: 17954986
Here is one way:

Adding a CheckBox column to your DataGrid
http://www.codeproject.com/aspnet/datagridcheckbox.asp?df=100&forumid=4431&exp=0&fr=26

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18131580
I believe that I answered the question, as ultimately asked on 11/13/2006.

Bob
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now