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"
OnRowCreated="gvShipping_RowCreated" 
        onselectedindexchanged="gvShipping_SelectedIndexChanged" 
        onrowdatabound="gvShipping_RowDataBound">
<Columns>


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

<asp:CommandField />

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


</Columns>
<EditRowStyle HorizontalAlign="Right" />
<HeaderStyle HorizontalAlign="Right" />
<RowStyle HorizontalAlign="Left" />
</asp:GridView>

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"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
          //  e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";

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

    }

Open in new window

LVL 5
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.

MlandaTCommented:
how about setting the SelectedRowStyle CssClass on your grid?
0

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:
thc
0
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
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.