Click here to Skip to main content
15,921,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a problem and not sure how to do it accordingly.
I have a GridView and if you select a row using the select command in the RowCommand event I change the color of the row to orange but how do I keep the rows that I have select orange when I page through the Gridview? And how do I unselect the rows so that they are not highlighted no more?

This is what I am using in my RowCommand event:
VB
index = Convert.ToInt32(e.CommandArgument)
          If selectedRow.BackColor = Color.Orange Then
            selectedRow.BackColor = System.Drawing.ColorTranslator.FromHtml("#738A9C")
            strPanr = selectedRow.Cells(1).Text
          Else
            selectedRow.BackColor = Color.Orange
            strPanr = selectedRow.Cells(1).Text
          End If


I tried to make an ArrayList of all the selected rows and store it in a Session variable but everytime I select a new row the ArrayList is empty and also the Session Variable.

Any help would be much appreciated
Posted
Updated 26-Feb-12 23:52pm

You can use viewstate for above code ....
 
Share this answer
 
Comments
Gericke Hoeksema 27-Feb-12 9:08am    
How will I use ViewState to add multiple values to it, like for intsance everytime I click on select values should be added and if I deselect it should be removed?
Dictionary<int,> dictionary = new Dictionary<int,>();

if(!Session["ListValue"])
{
       dictionary =(Dictionary<int,bool>)Session["ListValue"]
}

index = Convert.ToInt32(e.CommandArgument)
          If selectedRow.BackColor = Color.Orange Then
            selectedRow.BackColor = System.Drawing.ColorTranslator.FromHtml("#738A9C")
            strPanr = selectedRow.Cells(1).Text
         if(dictionary.ContainsKey(index))
          { 
        dictionary[index]=false;
          } 
else
{
dictionary.Add(index,false)
}
          Else
            selectedRow.BackColor = Color.Orange
            strPanr = selectedRow.Cells(1).Text
 if(dictionary.ContainsKey(index))
          { 
          dictionary[index]=true;
          } 
else
{
       dictionary.Add(index,true)
}

          End If
Session["ListValue"]=dictionary;
 
Share this answer
 

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