Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
hi,
In my application there is an option to select groups after selecting when i click on ok popup get closed. I want when i open that popup again the options which I selected should remain checked.
Posted 23-Mar-12 3:33am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What are you using for the popup? Using JQuery UI dialog the popup is constructed from a div element on your page, which unless you make a change any of the elements, will still have the same values no matter how many times it is displayed until the page is refreshed.
  Permalink  
Comments
betu.009 at 23-Mar-12 9:37am
   
modelpopup extender i m using for popup
Mark Nischalke at 23-Mar-12 18:28pm
   
The element used for the popup is on the page. As long as that page does not get refreshed the values will remain.
 
See this for how to handle checkboxes in GridView
http://www.codeproject.com/Articles/2580/DataGridDemo
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
You need to follow two steps.
 

1.On Ok_Button_Click Event Store the Checkbox Values in session.
 Session["Checkbox1"]= Checkbox1.Checked
 
2. In Page Load ( When PopUp opens) you need need to retrieve values back If it is already checked from the session.
 
If(!Page.IsPostback){
 
if(Session["Checkbox1"]!=null)
{
Checkbox1.Checked=bool.Parse( Session["Checkbox1"].ToString());
}
 
       }
 
hope it helps
 

In that Case You can save the value of checkboxes in Session on Ok Click and retrieve them from Session on PageLoad
 

here is the example code.
 
on Button Click
 
bool[] values = new bool[GridView1.Rows.Count];
 
        CheckBox chb; 
        int count = 0; 
        for (int i = 0; i < GridView1.Rows.Count; i++)
 
        { 
            chb = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
 
            if (chb != null) 
            { 
                values[i] = chb.Checked; 
            } 
        } 
        Session["GridValues"] = values; 
 

on Page Load
 
 
 
if (Session["GridValues" ] !=null) 
        { 
            CheckBox chb; 
            bool[] values = (bool[])Session["GridValues"];
 
            for (int i = 0; i < GridView1.Rows.Count; i++)
 
            { 
                chb = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
 
                chb.Checked = values[i]; 
            } 
        } 
 

Let me know if it works for you.
 
Thanks
  Permalink  
v2
Comments
betu.009 at 23-Mar-12 9:25am
   
but i am using a check box in a gridview's itemtemplate property. i mean every grid view row contains a checkbox. it that case what should i do?
Hammad Abbasi at 23-Mar-12 11:12am
   
Answer Improved According to your scenario.
Hope it Helps
Mark Nischalke at 23-Mar-12 18:23pm
   
Completely unnecessary to use session. This will bloat the application and cause poor performance. A horrendously poor solution.
 
See this for how to handle checkboxes in gridview
http://www.codeproject.com/Articles/2580/DataGridDemo
betu.009 at 24-Mar-12 0:19am
   
to Hammad Abbasi :- Thanks a lot. It works. You solved a big problem of mine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 584
1 Maciej Los 275
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 23 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100