Visual Studio - 使用JQuery Server Side使表行可单击

时间:2014-12-08 14:30:56

标签: jquery html vb.net

我试图获得一些帮助,我可以使用JQuery函数使下表行可单击。我已经尝试在函数中使用通常的onClick or.click但是没有任何事情发生在我调用的表的哪一部分。该表放在一个内,所以我发现很难使所有单独的行都可以点击。

如果我用通常的HMTL方式创建表格,我确信我能够完成此操作,但我需要你的帮助。

我的.aspx代码......

<%@ Page Title="" Language="VB" MasterPageFile="~/UserMast.master" AutoEventWireup="false" CodeFile="ViewDuplicateNames.aspx.vb" Inherits="ViewDuplicateNames" %>

    <p id="duplicatePara">Users with the same combination</p>

<div id="vTable">
    <asp:PlaceHolder ID="duplicateResults" runat="server" ></asp:PlaceHolder>
</div>

我的aspx.vb代码......

Protected Sub buttonSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonSearch.Click

    Dim dsResults As New DataSet
    Dim dt As DataTableReader


    dsResults = SearchResults(sLog.Value.ToString, sfirstName.Value.ToString, slastName.Value.ToString, sNumber.Value.ToString, sVal.Value.ToString)
    dt = dsResults.CreateDataReader


    Dim tb As New Table
    Dim tr As New TableRow
    Dim tc As New TableCell
    Dim lb As New Label
    Dim iCount As Integer = 1



    tb.CssClass = "tableStyle"
    tb.CellPadding =
    tb.CellSpacing = 0


    If dt.HasRows = True Then

        tr = New TableRow
        tr.CssClass = "tabHeader"
        tc = New TableCell
        lb = New Label

        lb.Text = "Log"
        tc.Controls.Add(lb)
        tr.Controls.Add(tc)

        tb.Controls.Add(tr)


        tr.CssClass = "tabHeader"
        tc = New TableCell
        lb = New Label

        lb.Text = "Staff"
        tc.Controls.Add(lb)
        tr.Controls.Add(tc)

        tb.Controls.Add(tr)

        tr.CssClass = "tabHeader"
        tc = New TableCell
        lb = New Label

        lb.Text = "Family Name"
        tc.Controls.Add(lb)
        tr.Controls.Add(tc)

        tb.Controls.Add(tr)


        tr.CssClass = "tabHeader"
        tc = New TableCell
        lb = New Label

        lb.Text = "First name"
        tc.Controls.Add(lb)
        tr.Controls.Add(tc)

        tb.Controls.Add(tr)


        tr.CssClass = "tabHeader"
        tc = New TableCell
        lb = New Label

        lb.Text = "Middlename"
        tc.Controls.Add(lb)
        tr.Controls.Add(tc)

        tb.Controls.Add(tr)

        tr.CssClass = "tabHeader"
        tc = New TableCell
        lb = New Label

        lb.Text = "DOB"
        tc.Controls.Add(lb)
        tr.Controls.Add(tc)

        tb.Controls.Add(tr)

        tr.CssClass = "tabHeader"
        tc = New TableCell
        lb = New Label

        lb.Text = "Number"
        tc.Controls.Add(lb)
        tr.Controls.Add(tc)

        tb.Controls.Add(tr)

        tr.CssClass = "tabHeader"
        tc = New TableCell
        lb = New Label

        lb.Text = "Job"
        tc.Controls.Add(lb)
        tr.Controls.Add(tc)

        tb.Controls.Add(tr)

        tr.CssClass = "tabHeader"
        tc = New TableCell
        lb = New Label

        lb.Text = "Loc"
        tc.Controls.Add(lb)
        tr.Controls.Add(tc)

        tb.Controls.Add(tr)

        tr.CssClass = "tabHeader"
        tc = New TableCell
        lb = New Label

        lb.Text = "Site"
        tc.Controls.Add(lb)
        tr.Controls.Add(tc)

        tb.Controls.Add(tr)

        tr.CssClass = "tabHeader"
        tc = New TableCell
        lb = New Label

        lb.Text = "Comments"
        tc.Controls.Add(lb)
        tr.Controls.Add(tc)

        tb.Controls.Add(tr)

        Do While dt.Read


            tr = New TableRow

            If iCount = 1 Then
                tr.CssClass = "rowStyle1"
                iCount = 0
            Else
                tr.CssClass = "rowStyle2"
                iCount = 1
            End If



            tc = New TableCell
            tc.CssClass = "rowCell"
            lb = New Label

            lb.Text = dt.Item("log").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)
            tb.Controls.Add(tr)


            'tr = New TableRow
            tc = New TableCell
            tc.CssClass = "rowCell"
            lb = New Label

            lb.Text = dt.Item("staff").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)
            tb.Controls.Add(tr)


            ' tr = New TableRow
            tc = New TableCell
            tc.CssClass = "rowCell"
            lb = New Label

            lb.Text = dt.Item("surname").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)
            tb.Controls.Add(tr)


            'tr = New TableRow
            tc = New TableCell
            tc.CssClass = "rowCell"
            lb = New Label

            lb.Text = dt.Item("forename").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)
            tb.Controls.Add(tr)


            'tr = New TableRow
            tc = New TableCell
            tc.CssClass = "rowCell"
            lb = New Label

            lb.Text = dt.Item("middlename").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)
            tb.Controls.Add(tr)


            'tr = New TableRow
            tc = New TableCell
            tc.CssClass = "rowCell"
            lb = New Label

            lb.Text = dt.Item("dob").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)
            tb.Controls.Add(tr)

            'tr = New TableRow
            tc = New TableCell
            tc.CssClass = "rowCell"
            lb = New Label

            lb.Text = dt.Item("num").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)
            tb.Controls.Add(tr)

            'tr = New TableRow
            tc = New TableCell
            tc.CssClass = "rowCell"
            lb = New Label

            lb.Text = dt.Item("pos").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)
            tb.Controls.Add(tr)

            'tr = New TableRow
            tc = New TableCell
            tc.CssClass = "rowCell"
            lb = New Label

            lb.Text = dt.Item("loc").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)
            tb.Controls.Add(tr)

            'tr = New TableRow
            tc = New TableCell
            tc.CssClass = "rowCell"
            lb = New Label

            lb.Text = dt.Item("site").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)
            tb.Controls.Add(tr)

            'tr = New TableRow
            tc = New TableCell
            tc.CssClass = "rowCell"
            lb = New Label

            lb.Text = dt.Item("comments").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)
            tb.Controls.Add(tr)

        Loop
        dt.Close()
        dsResults.Dispose()

        placeResults.Controls.Add(tb)

    Else

        noResultOutput.Text = "No User Account Located"

    End If


End Sub

我道歉很长。

如果我遗漏了任何有助于你的事情,请告诉我。

谢谢

2 个答案:

答案 0 :(得分:0)

我能想到的一种方法是在每个TableRow上设置ClientID。

tr = New TableRow
tr.ClientID = "tableRowID" 

然后在ASP页面上添加属性以设置静态ClientIdMode

<%@ Page Title="" Language="VB" MasterPageFile="~/UserMast.master" .... ClientIDMode="Static" %>

现在,您应该能够使用jQuery的每一行的ID进行点击事件。

$('#tableRowID').click(function() {
        var href = $(this).find("a").attr("href");
        if(href) {
            window.location = href;
        }
    });

答案 1 :(得分:0)

我找到了一种方法,可以使每一行都可以点击并显示警告。我一直无法找到关于如何在点击后显示隐藏按钮的解决方案,但我认为这可以通过JQuery Accordian完成?

我可以点击行的解决方案;

tr = New TableRow

            tr.Attributes.Add("onClick", "testMe('" & dt.Item("sLog").ToString & "')")

然后在HTML方面;

<script>
function testMe(myLogin) {

    alert(myLogin);
}


</script>