在中继器中整行可选
我有以下内容:有几行的中继器。每行都以链接按钮开头,我可以使用它导航到另一个页面。我现在想做的是,我可以使用链接按钮的相同单击功能来单击整行。 这是我的中继器:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)