Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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.
 
Share this answer
 
Comments
betu.009 23-Mar-12 9:37am    
modelpopup extender i m using for popup
[no name] 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
Hi,

You need to follow two steps.


1.On Ok_Button_Click Event Store the Checkbox Values in session.
C#
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.

C#
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
C#
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

C#
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
 
Share this answer
 
v2
Comments
betu.009 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 23-Mar-12 11:12am    
Answer Improved According to your scenario.
Hope it Helps
[no name] 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900