使用Javascript onfocus在GridView中更改LinkButton背景色

使用Javascript onfocus在GridView中更改LinkButton背景色,javascript,asp.net,gridview,focus,highlight,Javascript,Asp.net,Gridview,Focus,Highlight,我试图在gridview中更改一行的背景色,当用户在这些行中进行制表操作并获得焦点和失去焦点时 我能够改变标签的前景色,(只是在测试这个),所以我相信这是可以做到的 我需要帮助编写javascript来捕获表行标题的ClientID 它可能看起来像:document.getElementById(“ 您可以通过组合JavaScript中的this对象和asp:GridView伪代码的RowDataBound事件来实现这一点 protected void ParticipantsGrid_RowD

我试图在gridview中更改一行的背景色,当用户在这些行中进行制表操作并获得焦点和失去焦点时

我能够改变标签的前景色,(只是在测试这个),所以我相信这是可以做到的

我需要帮助编写javascript来捕获表行标题的ClientID

它可能看起来像:document.getElementById(“
您可以通过组合
JavaScript
中的
this
对象和
asp:GridView
伪代码的
RowDataBound
事件来实现这一点

protected void ParticipantsGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.Header)
    {
        e.Row.Attributes.Add("onmouseover", "setfocus(this)");
        e.Row.Attributes.Add("onmouseout", "setblur(this)");
    }
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add("onmouseover", "setfocus(this)");
        e.Row.Attributes.Add("onmouseout", "setblur(this)");
    }
}
JavaScript

function setfocus(elm) {
    elm.style.color = "Red";
}
function setblur(elm) {
    elm.style.color = "Blue";
}

注:我在这里使用的是
onmouseover
onmouseout

您可以通过组合
JavaScript
中的
this
对象和
asp:GridView
伪代码的
RowDataBound
事件来实现这一点

protected void ParticipantsGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.Header)
    {
        e.Row.Attributes.Add("onmouseover", "setfocus(this)");
        e.Row.Attributes.Add("onmouseout", "setblur(this)");
    }
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add("onmouseover", "setfocus(this)");
        e.Row.Attributes.Add("onmouseout", "setblur(this)");
    }
}
JavaScript

function setfocus(elm) {
    elm.style.color = "Red";
}
function setblur(elm) {
    elm.style.color = "Blue";
}

注:我在这里使用的是
onmouseover
onmouseout

谢谢你的回复。谢谢你的回复。我不确定这将如何工作???当用户使用tab键滚动行时(不使用鼠标),链接按钮“onfocus”调用javascript函数“setheaderfunction”“这会告诉rowdatabound事件发生。不确定。我正在寻找一种javascript,它可以精确定位具有焦点的gridview行属性并更改颜色。感谢您的回复。感谢您的回复。我不确定当用户使用tab键(不使用鼠标)滚动行时,这将如何工作??”LinkButton“onfocus”调用javascript函数“setheaderfunction”,该函数告诉rowdatabound事件发生。不确定。我正在寻找一种javascript,它可以精确定位具有焦点的gridview行属性并更改颜色。