C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






changing grid view row colors in two different times


Posted Date: 17 Jun 2008    Resource Type: Code Snippets    Category: ASP.NET GridView

Posted By: komaladevi       Member Level: Gold
Rating:     Points: 10



Change Color(bgColor) when row is selected::

Specify SelectedRowStyle attribute for the gridview.

Here it is how to specify SelectedRowStyle.


<asp:gridview DataKeyNames="RID" runat="server" ID="gridview1" AutoGenerateColumns="false" SkinID="gridView">

<SelectedRowStyle BackColor="#b2cffb" />

<Columns>

<asp:CommandField ShowSelectButton="true" />
<asp:BoundField HeaderStyle-Width="20%" ItemStyle-Width="20%" DataField="RequestType" HeaderText="Request Type" />
<asp:BoundField HeaderStyle-Width="20%" ItemStyle-Width="20%" DataField="Department" HeaderText="Department" />

</columns>

</asp:gridview>

If you want that no row should be selected on particular event then use gvRequest.selectedIndex = -1 .


change row's bgColor when mouse over gridview ::

Add attributes on "onMouseOver" & "onMouseOut" event of gridview's row and call javascript function and pass the clientid of row to this function.


protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "javascript:highlightrow('" + e.Row.ClientID + ');"); e.Row.Attributes.Add("onmouseout", "javascript:deselectrow('" + e.Row.ClientID + "','" + e.Row.RowIndex + "');");
}
}

Here is the javascript function.

function highlightrow(ctrlId)
{
var obj = document.getElementById(ctrlId);
obj.className ="highlightedRow";
}

function deselectrow(ctrlId,rowNum)
{
var obj = document.getElementById(ctrlId);

if ( parseInt(rowNum)%2 == 0)
obj.className ="GridViewItem";
else
obj.className ="GridViewAlternatingItem";
}












Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to do Color Change of Row of GridView on Select & Open a New Page of Selected Row Item
Previous Resource: Binding XML Data to the GridView
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET GridView


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use