itproem
asked on
How to change the color of the row in GridView OnMouseClick
Hello experts,
How to change the color of the row in GridView OnMouseClick (Visual C# ASP.NET web application)
I implemented this example:
http://gridviewguy.com/ArticleDetails.aspx?articleID=174
and it's working, but in this example row changes the color on click,
and it turns back to default color when you click again.
But I need this scenario: when you click/select one row1 it will become yellow (in this case),
and after clicking another row2, the previous selected row1 will turn back to default color without clicking it again, and of course, the new clicked row2 will become yellow. So, only one row can be colored at the same time because I want to see which row is selected.
Thanks
How to change the color of the row in GridView OnMouseClick (Visual C# ASP.NET web application)
I implemented this example:
http://gridviewguy.com/ArticleDetails.aspx?articleID=174
and it's working, but in this example row changes the color on click,
and it turns back to default color when you click again.
But I need this scenario: when you click/select one row1 it will become yellow (in this case),
and after clicking another row2, the previous selected row1 will turn back to default color without clicking it again, and of course, the new clicked row2 will become yellow. So, only one row can be colored at the same time because I want to see which row is selected.
Thanks
see whether the following example can work for you..
do you want only mouseclick or will mouseover and mouseout work for you??
https://www.experts-exchange.com/questions/22690077/Mouseover-hyperlink-effect-on-GridView-row.html
do you want only mouseclick or will mouseover and mouseout work for you??
https://www.experts-exchange.com/questions/22690077/Mouseover-hyperlink-effect-on-GridView-row.html
ASKER
I really need mouseclick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
If I'll use SelectedRowStyle-xxx in XYX procedure, should I then use OnSelectedIndexChanged ="XYX" ?
No.
Just in your rowcommand event or mouseclick event specify
yourGridView.SelectedIndex = Convert.ToInt32(e.CommandA rgument);
(or something like it depends on the event) (e.CommandArgument is from rowcommand event)
Just in your rowcommand event or mouseclick event specify
yourGridView.SelectedIndex
(or something like it depends on the event) (e.CommandArgument is from rowcommand event)
Static and rollover effect code
Statically you can define in your gridview.
<SelectedRowStyle BackColor="#C0D2DD" />
For rollover color change do like this.
protected void GridView2_RowDataBound(obj ect sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow )
{
e.Row.Attributes.Add("onmo useover", "this.style.backgroundColo r='dee0aa' ");
e.Row.Attributes.Add("onmo useout", "this.style.backgroundColo r='ebeccd' ");
}
}
Statically you can define in your gridview.
<SelectedRowStyle BackColor="#C0D2DD" />
For rollover color change do like this.
protected void GridView2_RowDataBound(obj
{
if (e.Row.RowType == DataControlRowType.DataRow
{
e.Row.Attributes.Add("onmo
e.Row.Attributes.Add("onmo
}
}
SelectedRowStyle-xxx properties of GridView. (I would suggest you to use css or skin file)
Then in your code, just specify which row is current selected.
SelectedIndex or SelectedRow property could be used.