views:

24

answers:

3

i have two gridviews 1) master and 2) detail in my master gridview with few columns in it and a hyperlink so when the user click on the hyperlink (master gridview) i want the row to be highlight but below codes does not hold the highlighted row after it does the postback, how do i make sure that its highlight even after it does postback?

protected void gvReport_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C2D69B'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
                e.Row.Attributes.Add("style", "cursor:pointer;");
                //e.Row.Attributes.Add("onclick", "location='patron_detail.aspx?id=" + e.Row.Cells[0].Text + "'");
            } 

    } 

<asp:GridView runat="server" ID="gvReport" AutoGenerateColumns="False" CssClass="gv"
                        DataSourceID="LDS_POReport" Width="880px" AllowPaging="true" AllowSorting="true"
                        OnRowCreated="gvReport_RowCreated" OnRowDataBound="gvReport_RowDataBound" DataKeyNames="Id" PageSize="15">
                        <PagerStyle HorizontalAlign="Left" CssClass='header' BackColor="#E5EAF3" ForeColor="Black" />
                        <PagerSettings Mode="NumericFirstLast" />
                        <EmptyDataTemplate>
                            No Items</EmptyDataTemplate>
                        <Columns> 
                            <asp:TemplateField HeaderText="Name" SortExpression="Name">
                                <ItemTemplate>
                                    &nbsp;
                                    <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Number Of Items" SortExpression="NumberOfItems">
                                <ItemTemplate>
                                    <a href='Officer.aspx?Id=<%# Eval("Id") %>'>
                                        <%# Eval("NumberOfItem")%>
                                    </a>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
A: 

just put a row index in query string and read it after the postback, then select the row based on index and change the color...

Fabio Beoni
i have index in the querystring and where do you read it after the postback? and select row?
Abu Hamzah
Set it in gvRowDataBound. if(Request.QueryString["rowindex"] == e.Row.RowIndex) { //set row background style }
clifgriffin
Abu Hamzah
Have you set a breakpoint to see how the values are comparing in real time? Also, my original example is probably not great since querystring would return a...string... Add .ToString() to e.Row.RowIndex.
clifgriffin
A: 

sorry for question... are you sure that you check between 2 integer values?... and if yes... in the html that you have, do you have the background color in the TD elements of the table? If you have the color code in the html code, maybe it's a problem of css style definition.

Fabio Beoni
A: 

pls give a good css template to row style

Vishnu K B