【问题标题】:retrieving anchor's color on server side在服务器端检索锚点的颜色
【发布时间】:2014-06-10 20:50:12
【问题描述】:

我正在服务器端检索 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 的第一行,颜色是 red 。但它返回“”。有什么解决办法吗?

【问题讨论】:

  • 旁注:您不需要在单元格上使用FindControl,因为GridViewRow 是包含唯一ID 的NamingContainer。所以这就足够了:r.FindControl("lkdelete").

标签: javascript asp.net vb.net hyperlink


【解决方案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

【讨论】:

    猜你喜欢
    • 2022-07-07
    • 2022-12-16
    • 1970-01-01
    • 2015-04-13
    • 2018-08-04
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    相关资源
    最近更新 更多