使用vb-在网格视图中选择复选框后获取行值,以避免在每次选择时刷新页面

getting the value of a row in a gridview after selecting its checkbox using vb- to avoid refreshing the page at each select

本文关键字:选择 刷新 视图 网格 vb- 复选框 使用 获取      更新时间:2023-09-26

我有带有checkbox on evryrow的aspx gridview,需要的是每当我们检查任何行时,应该启动query以更改特定代理-每行由agentID, Pass, Status- to Paid Status组成。使用javascript

我需要知道的是how to loop to get the Checked rowget the ID of the row checked,这样我就可以得到这一行中Agent的ID,这样我就可以更新它的状态。使用javascript

我在stackflow上发现了类似的东西:谢谢你

获取GridView在Javascript中选定的row DataKey

但这不是我的情况,需要的是在一个复选框的检查,javascript函数应该启动,通过它我可以在网格视图中更新选定的行有这一行的索引和这一切,以避免刷新页面。

您可以这样尝试.....查找行索引…

Private Function getCellControl(ByVal , As rowIdx, ByVal Unknown As colIdx) As function
    Dim gridCell As var = getGridColumn(rowIdx, colIdx)
    Dim type As var = Nothing
    Dim typePos As var
    Dim ctrId As var
    Dim idPos As var
    Dim delPos As var
    Dim inHTML As var
    Dim buf As var
    Dim chkStatus As var
    Dim statPos As var
    If (Not (gridCell) Is Nothing) Then
        inHTML = gridCell.innerHTML
        typePos = inHTML.indexOf("type")
        If (typePos > 0) Then
            typePos = (typePos + 5)
            buf = inHTML.substring(typePos)
            delPos = buf.indexOf(" ")
            If (delPos > 0) Then
                type = inHTML.substring(typePos, (typePos + delPos))
                If (type = "checkbox") Then
                    idPos = inHTML.indexOf("id")
                    If (idPos > -1) Then
                        idPos = (idPos + 3)
                        ctrId = inHTML.substring(idPos, (typePos - 5))
                    End If
                    statPos = buf.indexOf(" ")
                    If (statPos > -1) Then
                        buf = buf.substring((statPos + 1))
                        delPos = buf.indexOf(" ")
                        chkStatus = buf.substring(0, delPos)
                    End If
                End If
            End If
        End If
    End If
    Return ctrId
End Function

你可以使用jQuery:

$("#<%=GridView1.ClientID%> input[type='checkbox']").click(function(){
    if ($(this).is(":checked")){
        alert($(this).closest("tr").attr("id"));
    }
});