Question

I am retrieving the color of the html anchor control on the server side. following is my tried code

Design:

<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

here at 1st row of gridview the color is red . but it returns "". any solution?

Was it helpful?

Solution

make few changes on your code. add a hidden field on your page.

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(instead of for loop)

pid = CType(gridview.Rows(hsingle_del.Value).FindControl("lblposid"), Label).Text
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top