How to select an entire row in a GridView and have the selection "stick" through a page refresh

I've managed to get the rows in the gridview to "highlight" as I roll-over them, but now I want to be able to select a row and have it turn some color.  I also want that color to "stick" even after a page refresh.

I assume this is possible, but I am not sure how to go about it.

How might I modify my existing code?

<asp:GridView ID="gvShipping" runat="server" AutoGenerateColumns="False" DataKeyNames="TABLE"
OnRowCommand="gvShipping_RowCommand" Visible="False" GridLines="None" CssClass="grid-view"
Width="350px" BorderStyle="Solid" BorderWidth="1px" EnableModelValidation="True"

<asp:TemplateField HeaderText="Select Shipping Method" HeaderStyle-HorizontalAlign="Right">
<asp:TextBox ID="textBox1" runat="server" Text='<%# Bind("DISPLAY") %>'></asp:TextBox>
<asp:Label CommandName="Select" runat="server" ID="lblDisplay" Text='<%# Bind("DISPLAY") %>'></asp:Label>
    <HeaderStyle HorizontalAlign="Left" />
    <ItemStyle HorizontalAlign="Left" />

<asp:CommandField />

<asp:TemplateField HeaderText="Amount" HeaderStyle-HorizontalAlign="Right">
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("AMOUNT") %>'></asp:TextBox>
<asp:Label ID="lblAmount" runat="server" Text='<%# Bind("AMOUNT") %>'></asp:Label>
    <HeaderStyle HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" Width="60px" />

<EditRowStyle HorizontalAlign="Right" />
<HeaderStyle HorizontalAlign="Right" />
<RowStyle HorizontalAlign="Left" />

Open in new window

code behind:
    protected void gvShipping_RowCreated(object sender, GridViewRowEventArgs e)
        //Add CSS class on header row.
        if (e.Row.RowType == DataControlRowType.Header)
            e.Row.CssClass = "header";

        //Add CSS class on normal row.
        if (e.Row.RowType == DataControlRowType.DataRow &&
                  e.Row.RowState == DataControlRowState.Normal)
            e.Row.CssClass = "normal";

        //Add CSS class on alternate row.
        if (e.Row.RowType == DataControlRowType.DataRow &&
                  e.Row.RowState == DataControlRowState.Alternate)
            e.Row.CssClass = "alternate";

    protected void gvShipping_SelectedIndexChanged(object sender, EventArgs e)
    {  // ((GridViewRow)sender).CssClass = "alternate";

    protected void gvShipping_RowDataBound(object sender, GridViewRowEventArgs e)
        if (e.Row.RowType == DataControlRowType.DataRow)
          //  e.Row.Attributes["onmouseover"] = "'hand';'underline';";
          //  e.Row.Attributes["onmouseout"] = "'none';";

            e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gvShipping, "Select$" + e.Row.RowIndex);


Open in new window

Tom KnowltonWeb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

how about setting the SelectedRowStyle CssClass on your grid?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.