在中继器中整行可选

发布于 2024-12-24 22:03:31 字数 2901 浏览 0 评论 0原文

我有以下内容:有几行的中继器。每行都以链接按钮开头,我可以使用它导航到另一个页面。我现在想做的是,我可以使用链接按钮的相同单击功能来单击整行。 这是我的中继器:

    <table>
    <tr>
    <td>
<asp:Repeater ID="rptTasks" runat="server" onitemcommand="rptTasks_ItemCommand" 
    onitemdatabound="rptTasks_ItemDataBound" onitemcreated="rptTasks_ItemCreated">
<HeaderTemplate>
<table>
<tr>
<td colspan="8"></td>
<td colspan="2"> </td>
</tr>
</HeaderTemplate>
<ItemTemplate>

<tr style="cursor: pointer" onclick="Select(this);">
<td>
<asp:LinkButton ID="SelectRow" runat="server" CommandName="SelectRow" Text="Test" />
<asp:HyperLink ID="LnkTaskID1" runat="server"  CommandName="SelectRow" Text='<%# Eval("TaskID") %>' Font-Underline="True" /></td>
<td><asp:Label ID="StatusLabel1" runat="server" Text='<%# LocalizeStatusBinding(Eval("Status", "{0}")) %>' /></td>

</tr>

</ItemTemplate>
<AlternatingItemTemplate>
<tr style="cursor: pointer" onclick="Select(this);">
<td>
<asp:LinkButton ID="SelectRow" runat="server" CommandName="SelectRow" Text="Test" />
<asp:HyperLink ID="LnkTaskID1" runat="server"  CommandName="SelectRow" Text='<%# Eval("TaskID") %>' Font-Underline="True" /></td>
<td><asp:Label ID="StatusLabel1" runat="server" Text='<%# LocalizeStatusBinding(Eval("Status", "{0}")) %>' /></td>

</tr>

</table>
</AlternatingItemTemplate>
<FooterTemplate>
<tr>
<td colspan="5" align="left">
                    <asp:Label ID="lblCurrentPage" 
    runat="server"></asp:Label>
                </td>
                <td colspan="5" align="right">
                    <asp:HyperLink ID="lnkPrev" runat="server" Text="<< Prev"></asp:HyperLink>
                    <asp:HyperLink ID="lnkNext" runat="server" Text="Next>>"></asp:HyperLink>
                </td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
 </td>
 </tr>
 </table>

我还使用了 javascript 来获取所选行:

    <script type="text/javascript" >
function Select(obj) 
{ 
    obj.className = 'selected'; 
    var tbl = document.getElementById("table1") 
    var firstRow = tbl.getElementsByTagName("TR")[0]; 
    var oldRow = tbl.rows[firstRow.getElementsByTagName("input")[0].value];
    if (oldRow != null) 
    { 
        oldRow.className = ''; 
    } 
    firstRow.getElementsByTagName("input")[0].value = obj.rowIndex; 
}
    </script>

    <script type="text/C#" >
    onclick="this.getElementsByTagName('input')[0].clicked=true;
    </script>

当我给第二个表标签 id="table1" 时,我得到 jscript 错误,oldRow 未知

有人知道这个问题的解决方案吗?为了清楚起见:我想单击一行,然后导航,就像单击每行的第一个链接按钮一样。

提前致谢。

I have the following: repeater with a couple rows. each row starts with linkbutton with which can i navigate to another page. what I now want to do is that I can click the whole row with the same clicking functionality of the linkbutton.
Here is my Repeater:

    <table>
    <tr>
    <td>
<asp:Repeater ID="rptTasks" runat="server" onitemcommand="rptTasks_ItemCommand" 
    onitemdatabound="rptTasks_ItemDataBound" onitemcreated="rptTasks_ItemCreated">
<HeaderTemplate>
<table>
<tr>
<td colspan="8"></td>
<td colspan="2"> </td>
</tr>
</HeaderTemplate>
<ItemTemplate>

<tr style="cursor: pointer" onclick="Select(this);">
<td>
<asp:LinkButton ID="SelectRow" runat="server" CommandName="SelectRow" Text="Test" />
<asp:HyperLink ID="LnkTaskID1" runat="server"  CommandName="SelectRow" Text='<%# Eval("TaskID") %>' Font-Underline="True" /></td>
<td><asp:Label ID="StatusLabel1" runat="server" Text='<%# LocalizeStatusBinding(Eval("Status", "{0}")) %>' /></td>

</tr>

</ItemTemplate>
<AlternatingItemTemplate>
<tr style="cursor: pointer" onclick="Select(this);">
<td>
<asp:LinkButton ID="SelectRow" runat="server" CommandName="SelectRow" Text="Test" />
<asp:HyperLink ID="LnkTaskID1" runat="server"  CommandName="SelectRow" Text='<%# Eval("TaskID") %>' Font-Underline="True" /></td>
<td><asp:Label ID="StatusLabel1" runat="server" Text='<%# LocalizeStatusBinding(Eval("Status", "{0}")) %>' /></td>

</tr>

</table>
</AlternatingItemTemplate>
<FooterTemplate>
<tr>
<td colspan="5" align="left">
                    <asp:Label ID="lblCurrentPage" 
    runat="server"></asp:Label>
                </td>
                <td colspan="5" align="right">
                    <asp:HyperLink ID="lnkPrev" runat="server" Text="<< Prev"></asp:HyperLink>
                    <asp:HyperLink ID="lnkNext" runat="server" Text="Next>>"></asp:HyperLink>
                </td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
 </td>
 </tr>
 </table>

I have also used javascript to get the selected row:

    <script type="text/javascript" >
function Select(obj) 
{ 
    obj.className = 'selected'; 
    var tbl = document.getElementById("table1") 
    var firstRow = tbl.getElementsByTagName("TR")[0]; 
    var oldRow = tbl.rows[firstRow.getElementsByTagName("input")[0].value];
    if (oldRow != null) 
    { 
        oldRow.className = ''; 
    } 
    firstRow.getElementsByTagName("input")[0].value = obj.rowIndex; 
}
    </script>

    <script type="text/C#" >
    onclick="this.getElementsByTagName('input')[0].clicked=true;
    </script>

When i give the second table tag an id="table1" i get jscript error, oldRow unknown

Does someone know a solution for this issue? for clarity: I want clicking on an row and then navigating just like if I click on the first linkbutton of each row.

In advance thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拔了角的鹿 2024-12-31 22:03:31
    $(function () {
        SetNaigationToSearchList();
    }
  );

    function SetNaigationToSearchList() {
        $("tr td")
        .css("cursor", "pointer")//set the pointer cursor for table row
        .click(function () {

            $row = $(this).parent();               
            var ID = $("td", $row).eq(0).text();//Get the 0 th col value of the cliked index... 
           alert('clicked');
            }

        });
    }
    $(function () {
        SetNaigationToSearchList();
    }
  );

    function SetNaigationToSearchList() {
        $("tr td")
        .css("cursor", "pointer")//set the pointer cursor for table row
        .click(function () {

            $row = $(this).parent();               
            var ID = $("td", $row).eq(0).text();//Get the 0 th col value of the cliked index... 
           alert('clicked');
            }

        });
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文