norton127
asked on
Gridview row mouseover or mouse click
I am having a gridview in asp.net and i am using vb.net. I want row color to be changed if the use clicks on row of gridview or when user moves mouse on row.Please suggest the code
THe above is for chnage on rollover
THe below is for change on click
THe below is for change on click
<script type="text/javascript">
//variable that will store the id of the last clicked row
var previousRow;
function ChangeRowColor(row)
{
//If last clicked row and the current clicked row are same
if (previousRow == row)
return;//do nothing
//If there is row clicked earlier
else if (previousRow != null)
//change the color of the previous row back to white
document.getElementById(previousRow).style.backgroundColor = "#ffffff";
//change the color of the current row to light yellow
document.getElementById(row).style.backgroundColor = "#ffffda";
//assign the current row id to the previous row id
//for next row to be clicked
previousRow = row;
}
</script>
Following code will be required on GridView1_RowDataBound event
Collapse
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
e.Row.Attributes.Add("onclick", "javascript:ChangeRowColor('" & e.Row.ClientID & "')")
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
'FillDataTable is a function that will return a DataTable
'with some values and is available in the code for download.
Me.GridView1.DataSource = Me.FillDataTable()
Me.GridView1.DataBind()
End If
End Sub
50 points for this??... :(
ASKER
hi thank you Please send me the vb code i am eager to know about that
Please
Please
ASKER
I am unable to change C# code to VB it is difficult what is this stands for here how to change that or else please suggest me the mouse over in vb.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
just begin typing the above code in VS and it will prompt you with the right syntax. There is not much ifference between the VB and C# versions
ASKER
Thank you My friend.I Got the answer i am just giving backgroundcolor not backgroundColor.Due to C the grid is not displayed.IS this case sensitive ? Is it a javascript? Any how Thankyou for your Response and Can i get the code for getting popup menu by right click or clicking the gridview row? Plese help me in this regard also
<asp:GridView ID="gvNews"
runat="server"
AutoGenerateColumns="False
DataKeyNames="BlogID"
DataSourceID="SqlDataSourc
AllowPaging="True"
PageSize="20"
BorderStyle="None"
BorderWidth="0px"
Width="100%"
CellPadding="10"
CellSpacing="4"
ShowHeader="False"
OnRowCreated="gvNews_OnRow
>
</asp:GridView>
In your code behind, you will need to add a handler for this event. For my example, Im using alternating background colors on rows (which you should do too, it makes things so much more readable). This causes me to add a couple extra lines so that I make sure Im setting my rows back to the correct color on MouseOut
Open in new window