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"; }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|