在服务器端检索锚点的颜色

时间:2014-04-25 08:30:56

标签: javascript asp.net vb.net hyperlink

我正在检索服务器端的html锚控件的颜色。以下是我尝试过的代码

设计

<a id="lkdelete" onclick="SingleDel(this);" runat="server" style="font-weight:bold ">Delete</a>

使用Javascript:

function SingleDel(ctrl)
{
    var row=ctrl.parentNode.parentNode;//to get row containing image
    var rowIndex=row.rowIndex;//row index of that row.
    var hsingle_del=document.getElementById('<%hsingle_del.ClientId %>');
    hsingle_del.value=rowIndex;
    var modalPopupBehaviorCtrl = $find('bmpe');            
    modalPopupBehaviorCtrl.set_PopupControlID("pnlPopup");  
    modalPopupBehaviorCtrl.show();   
}

Vb.Net:

    Dim pid As String = ""
    For Each r As GridViewRow In gridview.Rows
        Dim lnk As HtmlAnchor = CType(r.Cells(1).FindControl("lkdelete"), HtmlAnchor)

        If lnk.Style("Color") = "Red" Then  
            pid = CType(r.FindControl("lblposid"), Label).Text
        End If
    Next

这里在gridview的第一行,颜色为红色。但它返回&#34;&#34;。任何解决方案?

1 个答案:

答案 0 :(得分:1)

对您的代码进行一些更改。在页面上添加隐藏字段。

function SingleDel(ctrl)
{
    var rowIndex=ctrl.offsetParent.parentNode.rowIndex-1;
    var hsingle_del=document.getElementById('<%=hsingle_del.ClientId %>');
    hsingle_del.value=rowIndex;
    var modalPopupBehaviorCtrl = $find('bmpe');            
    modalPopupBehaviorCtrl.set_PopupControlID("pnlPopup");  
    modalPopupBehaviorCtrl.show();   
}

vb(而不是for循环)

pid = CType(gridview.Rows(hsingle_del.Value).FindControl("lblposid"), Label).Text