Hi,
i have a gridview i need to highlight row on mouse over on the row and highlight the row when clicked , this time mouse over on other rows should not happen.
i have done with mouse over n out and also higglight row on clicking. But dont know how to perform mouse over on other rows should not happen when a row is highlighted.
This is my code
please help me asap...
thanks in advance
i have a gridview i need to highlight row on mouse over on the row and highlight the row when clicked , this time mouse over on other rows should not happen.
i have done with mouse over n out and also higglight row on clicking. But dont know how to perform mouse over on other rows should not happen when a row is highlighted.
This is my code
Code:
aspx.cs
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#00FF00';");
if (e.Row.RowIndex % 2 == 0)
{ // even
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FF8040';");
} // odd
else
{
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FF8040';");
}
e.Row.Attributes.Add("onclick", "onGridViewRowSelected('" + id.ToString() + "')");
}
id++;
}
aspx page
<script language="javascript" type="text/javascript">
var gridViewCtlId = '<%=GridView1.ClientID%>';
var gridViewCtl = null;
var curSelRow = null;
function getGridViewControl()
{
if (null == gridViewCtl)
{
gridViewCtl = document.getElementById(gridViewCtlId);
}
}
function onGridViewRowSelected(rowIdx)
{
var selRow = getSelectedRow(rowIdx);
if (curSelRow != null)
{
curSelRow.style.backgroundColor = '#ffffff';
}
if (null != selRow)
{
curSelRow = selRow;
curSelRow.style.backgroundColor = '#ff0022';
}
}
function getSelectedRow(rowIdx)
{
getGridViewControl();
if (null != gridViewCtl)
{
return gridViewCtl.rows[rowIdx];
}
return null;
}
</script>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowcreated="GridView1_RowCreated">
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%# Eval("Name")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Age">
<ItemTemplate>
<%# Eval("Age")%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Gender" DataField="Gender"/>
</Columns>
</asp:GridView>
please help me asap...
thanks in advance
Comment