如何在“删除链接"按钮上更改Datagrid行的颜色在Datagrid中单击
问题描述:
嗨
我有一个DataGrid,需要在单击Datagrid中的Delete LinkButton时更改datagrid中行的颜色.
请帮忙.
谢谢.
Hi
I am having a DataGrid and need to change the color of the row in datagrid on clicking the Delete LinkButton in Datagrid.
Please help.
ThanKs.
答
您可以通过在网格行的链接按钮的onClick上注入Javascript函数来执行以下操作.
要注入JS,您需要使用GridView的RowDataBound
,如下所示:
You can do the following by Injecting Javascript function on onClick of link button for a grid row.
For injecting JS, you need to useRowDataBound
of GridView, something like:
protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
DataControlRowType rtype = e.Row.RowType;
if (rtype == DataControlRowType.DataRow && rtype != DataControlRowType.Footer
&& rtype != DataControlRowType.Separator && rtype != DataControlRowType.Header
&& rtype != DataControlRowType.Pager)
{
// Highligh row on click of row
e.Row.Attributes.Add("onclick", "Highlight(this);");
}
}
针对任何事件(如鼠标悬停或链接按钮单击等)进行修改.
试试吧!
Modify it for any event like mouseover or link button click, etc.
Try!