分页时使GridViewRows突出显示 [英] Keep GridViewRows highlighted when paging
问题描述
我有一个问题,不确定如何相应地解决.
我有一个GridView,如果您在RowCommand事件中使用select命令选择了一行,我会将行的颜色更改为橙色,但是当我在Gridview中翻页时如何保持选择的行为橙色?以及如何取消选择行,以使它们不再突出显示?
这是我在RowCommand事件中使用的:
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:
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
我尝试制作所有选定行的ArrayList并将其存储在Session变量中,但是每次我选择新行时,ArrayList都是空的,Session变量也为空.
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
推荐答案
您可以在上述代码中使用viewstate....
You can use viewstate for above code ....
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;
这篇关于分页时使GridViewRows突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!