Hi! I have a gridview, with a button which when is pressed, the row is coloured. Only one row can be selected.
But when I change page, I lose the reference of the row and it´s uncoloured. Here´s an example of my code:
<asp:GridView ID="gvListaTit" runat="server" AutoGenerateColumns="False" DataKeyNames="ID_TITULO_DETALLE" GridLines="Both" HorizontalAlign="Center" EmptyDataText="No se han encontrado resultados." AllowPaging="True" OnPageIndexChanging="gvListaTit_PageIndexChanging" PageSize="3" CssClass="table table-bordered"> <Columns> <asp:BoundField DataField="ID_TITULO_DETALLE" HeaderText="ID_TITULO_DETALLE" /> <asp:BoundField DataField="DENOMINACION" HeaderText="Denominación" /> <asp:BoundField DataField="EXPEDIDO_POR" HeaderText="Expedido Por" /> <asp:TemplateField HeaderStyle-Width="65px"> <ItemTemplate> <asp:ImageButton ID="btnSeleccionar" runat="server" CssClass="btn btn-simple btn-accion" ImageUrl="~/Imagenes/Iconos/check_24.png" OnClick="Edit"/> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
protected void Edit(object sender, EventArgs e) { foreach (GridViewRow row1 in gvListaTit.Rows) { row1.BackColor = System.Drawing.Color.White; }
ImageButton btn = sender as ImageButton; GridViewRow row = btn.NamingContainer as GridViewRow; if (row.BackColor == System.Drawing.ColorTranslator.FromHtml("#83CFC6")) { row.BackColor = System.Drawing.Color.White; hididTitulo.Value = null; } else { row.BackColor = System.Drawing.ColorTranslator.FromHtml("#83CFC6"); hididTitulo.Value = row.Cells[0].Text;
}
How can I keep the selected row coloured when I change page? Thanks!