Does the CSS friendly GridView have problems showing selected rows?

Rate It (1)

Last post 10-24-2006 2:00 AM by angel eyes. 4 replies.

Sort Posts:

  • Does the CSS friendly GridView have problems showing selected rows?

    09-14-2006, 2:33 PM
    • Member
      215 point Member
    • angel eyes
    • Member since 11-25-2005, 1:22 AM
    • Posts 43

    It seems it doesn't render the selected rows.

    I tried using:

    <SelectedRowStyle BackColor="yellow" />

    both in the skin file and in the aspx file, and this is after trying to change the CSS marked ".MyGridView .AspNet-GridView table tbody tr.AspNet-GridView-Selected td"

    Crawling up the walls, started digging into the code, found out that:

    1. This doesn't occurr for all rows, just for the alternate ones. Normal items are rendered properly.
    2. The reason is simple: the adapter doesn't render a AspNet-GridView-Selected Class for the alternate ones, in fact, it doesn't give ANY class for the selected one and the one before, and the one after.

    this is a piece of the rendered HTML

    Before: (row number one selected, all is fine)

     
    <tbody>
    	<tr class=" AspNet-GridView-Selected ">
    		<td><a href="javascript:__doPostBack('GridView1','Select$0')">Select</a></td>
    		<td>Sinh</td>
    		<td>17416</td>
    		<td>31</td>
    		<td>1.7943</td>
    	</tr>
    	<tr class=" AspNet-GridView-Alternate ">
    		<td><a href="javascript:__doPostBack('GridView1','Select$1')">Select</a></td>
    		<td>Tanh</td>
    		<td>17448</td>
    		<td>31</td>
    		<td>1.7910</td>
    	</tr>
    	<tr>
    		<td><a href="javascript:__doPostBack('GridView1','Select$2')">Select</a></td>
    		<td>Truncate</td>
    		<td>18233</td>
    		<td>31</td>
    		<td>1.7139</td>
    	</tr>
    
      
    And after - row number 2 (alternate item) chosen:
    <tbody>
    	<tr>
    		<td><a href="javascript:__doPostBack('GridView1','Select$0')">Select</a></td>
    		<td>Sinh</td>
    		<td>17416</td>
    		<td>31</td>
    		<td>1.7943</td>
    	</tr>
    	<tr>
    		<td><a href="javascript:__doPostBack('GridView1','Select$1')">Select</a></td>
    		<td>Tanh</td>
    		<td>17448</td>
    		<td>31</td>
    		<td>1.7910</td>
    	</tr>
    	<tr>
    		<td><a href="javascript:__doPostBack('GridView1','Select$2')">Select</a></td>
    		<td>Truncate</td>
    		<td>18233</td>
    		<td>31</td>
    		<td>1.7139</td>
    	</tr>
    
     
  • Re: Does the CSS friendly GridView have problems showing selected rows?

    09-14-2006, 4:22 PM
    • Member
      215 point Member
    • angel eyes
    • Member since 11-25-2005, 1:22 AM
    • Posts 43

    Smile I continued...

    The problem originates in the GetRowClass function in GridViewAdapter.vb, the select-case there doesn't allow for the fact that

     DataControlRowState is actually a bitwise variable enum.

    You see:

    DataControlRowState.Alternate = 1 

    DataControlRowState.Selected = 2

    So when an alternate row is selected, the value passed here is 3, which isn't handled by the select-case.

    Until MS comes up with a better all-around code, I simply changed one line (number 13 in this post):

    1    Private Function GetRowClass(ByVal gridView As GridView, ByVal row As GridViewRow) As String
    2     Dim className As String = ""
    3    
    4     Select Case row.RowState
    5        Case DataControlRowState.Alternate
    6           className += " AspNet-GridView-Alternate "
    7           className += gridView.AlternatingRowStyle.CssClass
    8        Case DataControlRowState.Edit
    9           className += " AspNet-GridView-Edit "
    10          className += gridView.EditRowStyle.CssClass
    11       Case DataControlRowState.Insert
    12          className += " AspNet-GridView-Insert "
    13       Case DataControlRowState.Selected, DataControlRowState.Selected Or DataControlRowState.Alternate
    14          className += " AspNet-GridView-Selected "
    15          className += gridView.SelectedRowStyle.CssClass
    16    End Select
    17   
    18    Return className
    19   End Function
    
     
  • Re: Does the CSS friendly GridView have problems showing selected rows?

    09-14-2006, 8:57 PM
    • Contributor
      3,298 point Contributor
    • Russ Helfand
    • Member since 09-14-2005, 6:22 PM
    • Groovybits.com
    • Posts 741
    Good fix.  I'll include it in the next rev of the kit. Thanks, this was a valuable contribution.
    Russ Helfand
    Groovybits.com
  • Re: Does the CSS friendly GridView have problems showing selected rows?

    10-23-2006, 1:19 PM
    • Member
      27 point Member
    • kjarrodc
    • Member since 09-10-2006, 3:05 PM
    • Posts 4
    Thank you for this find.  I was able to apply the same fix to my website.
  • Re: Does the CSS friendly GridView have problems showing selected rows?

    10-24-2006, 2:00 AM
    • Member
      215 point Member
    • angel eyes
    • Member since 11-25-2005, 1:22 AM
    • Posts 43
    Hey, I'm glad it helped you. Thanks for posting this, too. Sometimes you want to contribute, and don't know if you've helped... So it feels good to know it did.
Page 1 of 1 (5 items)