ASP.NET ListView控件整行选择 [英] ASP.NET ListView full row select

查看:764
本文介绍了ASP.NET ListView控件整行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我玩弄使用一个GridView的ListView的,而不是完成一个复杂的目标。 ListView控件是帮助在很多方面,更是有code一个特定的位,我习惯使用与GridView的,不会不与ListView的工作。

So I am playing around with using a ListView instead of a GridView to accomplish a complicated goal. The ListView is helping in a lot of ways, but there is one particular bit of code I am used to using with GridView's that won't doesn't work with ListView's.

如果我必须在GridView在我行的一个不错的鼠标悬停动作,如果我想让用户点击任意位置成一排来选择它,我用的是OnRowDataBound事件做这样的事情。

If I have to have a nice mouse hover action on my rows in a GridView, and if I want to let a user click anywhere in a row to select it, I use the OnRowDataBound event and do something like this

e.Row.Attributes["onmouseover"] = "this.oldClass=this.className;this.className='hover';";
e.Row.Attributes["onmouseout"] = "this.className=this.oldClass;";
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(gdvBuildings, "Select$" + e.Row.RowIndex.ToString());

它与GridView的伟大工程。与ListView我可以用OnItemDataBound事件,但似乎并没有成为一个具有属性数组中添加任何控制。

It works great with GridViews. With the ListView I can use the OnItemDataBound event, but there doesn't seem to be any control that has an Attributes array to add to.

有谁知道的等效的解决方案,以便有一个ListView鼠标悬停和全行的点击?

Does anyone know of an equivalent solution to allow for mouse hover and full row click with a ListView?

推荐答案

在一个ListView要创建的行自己,这样就可以直接在该行添加此功能,这样的事情。

On a ListView you are creating the row yourself so you can add this functionality directly on the row, something like this.

<asp:ListView ID="ListView3" runat="server">
<ItemTemplate>
  <tr onmouseover="this.oldClass=this.className;this.className='hover';" onmouseout="this.className=this.oldClass;" onclick='<%# Page.ClientScript.GetPostBackClientHyperlink(gdvBuildings, "Select$" + Container.DataItemIndex.ToString()) %>' >
    <td>
      <asp:Label ID="Label7" runat="server" Text='<%# Eval("ClientNumber") %>' />
    </td>
    <td>
      <asp:Label ID="CityNameLabel" runat="server" Text='<%# Eval("FullName") %>' />
    </td>
  </tr>
</ItemTemplate>
<LayoutTemplate>
  <table id="itemPlaceholderContainer" runat="server" border="0" style="">
    <tr id="itemPlaceholder" runat="server">
    </tr>
  </table>
</LayoutTemplate>
</asp:ListView>

这篇关于ASP.NET ListView控件整行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆