I’m using the following code to highlight a row the user clicks on in gridview (and unhighlights previously selected row):
protected void PartListRowClicked(object sender, GridViewRowClickedEventArgs e)
{
pnewrow = (GridViewRow)PartList.Rows[e.Row.RowIndex];
pnewrow.BackColor = Color.Blue;
pnewrow.ForeColor = Color.White;
if (poldrow != null)
{
poldrow.BackColor = Color.Empty;
poldrow.ForeColor = Color.Black;
}
poldrow = pnewrow;
}
However, the poldrow object is always reset to null after a postback (clicking causes a postback). Is there a way to save the row index between postbacks? Or alternatively, is there a better way to implement this functionality?
Thanks
You could store the value in
ViewStateorSession: