Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Highlight row without postback?

Author  Topic 

jhermiz

3564 Posts

Posted - 2008-01-27 : 00:00:35
Maybe its getting too late (midnight) and I've practically read and googled every frigging article on gridviews and I cant find one on what I want.

I have a checkbox control in my grid view like so:


<asp:TemplateField>
<ItemTemplate><asp:CheckBox ID="chkSelector" runat="server" /> </ItemTemplate> </asp:TemplateField>


I also dont want auto post back set to true on this because I do not want to post back to the server when doing what I am trying to do.
I also use alternate row colors and highlighting when one rolls over a data grid row:


Protected Sub gvRequests_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvRequests.RowCreated
Dim onmouseoverStyle As String = "this.style.backgroundColor='#D4EDFF'"
Dim onmouseoutStyle As String = "this.style.backgroundColor='@BackColor'"
Dim rowBackColor As String = String.Empty

If (e.Row.RowType = DataControlRowType.DataRow) Then

If e.Row.RowState = DataControlRowState.Alternate Then
rowBackColor = System.Drawing.ColorTranslator.ToHtml(Me.gvRequests.AlternatingRowStyle.BackColor).ToString()
Else
rowBackColor = System.Drawing.ColorTranslator.ToHtml(Me.gvRequests.RowStyle.BackColor).ToString()
End If
e.Row.Attributes.Add("onmouseover", onmouseoverStyle)
e.Row.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", rowBackColor))
End If
End Sub


That above part makes this all the more difficult...Anyhow what I want to accomplish is when you check the check box in the data grid it highlights the checked row to say yellow. If you uncheck the checkbox then it just takes the yellow away and leaves it like it was originally. I'll prolly need some JS for this?

Can anyone help or does anyone have a current solution for something like this...


Weblog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]

jhermiz

3564 Posts

Posted - 2008-01-27 : 00:41:35
Well I sort of got it...and I mean sort of...
But there is still one issue...

What I did was created a function in javascript like so:


<script language="javascript" type="text/javascript">
function ChangeRowColor(obj)
{
if (obj.checked) {
obj.parentElement.parentElement.style.backgroundColor='Yellow';
}
else
{
obj.parentElement.parentElement.style.backgroundColor='White';
}
}

</script>


In my datagrid column for this check box I call this with:


<ItemTemplate>
<asp:CheckBox ID="chkSelector" onclick="ChangeRowColor(this)" runat="server" />
</ItemTemplate>



When I do click on the checkbox it does make the background row color yellow. HOWEVER, once I roll away from this row onto another row or anywhere else on the page the yellow is gone...and this is because of the rowcreated event that initially adds the onmouseover attributes for the gridview rows which is this:


Protected Sub gvRequests_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvRequests.RowCreated
Dim onmouseoverStyle As String = "this.style.backgroundColor='#D4EDFF'"
Dim onmouseoutStyle As String = "this.style.backgroundColor='@BackColor'"
Dim rowBackColor As String = String.Empty

If (e.Row.RowType = DataControlRowType.DataRow) Then
If e.Row.RowState = DataControlRowState.Alternate Then
rowBackColor = System.Drawing.ColorTranslator.ToHtml(Me.gvRequests.AlternatingRowStyle.BackColor).ToString()
Else
rowBackColor = System.Drawing.ColorTranslator.ToHtml(Me.gvRequests.RowStyle.BackColor).ToString()
End If
e.Row.Attributes.Add("onmouseover", onmouseoverStyle)
e.Row.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", rowBackColor))
End If
End Sub


Issue is I dont want to get rid of this function as I like the mouse over effects on the grid. But because of this the highlight goes away :(. Any suggestions ?

Thanks,

Weblog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page

jhermiz

3564 Posts

Posted - 2008-01-28 : 08:08:39
Pss pss Jeff you there :)?

I think my issue is that I am adding this attribute (onMouseOver and onMouseOut) to my grid view control. Hence when I click on the check box I just get the yellow flicker and it goes back to normal when I move away from the row. I dont think there is any way to fix this?

Weblog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page
   

- Advertisement -