Asp.net 禁用列表视图上的选择

Asp.net 禁用列表视图上的选择,asp.net,listview,Asp.net,Listview,我想根据行中的其他数据禁用ListView的Select命令。例如,如果UserStatus是“T”,我想灰显Select超链接并阻止选择该行 我在GridView中通过RowCreated事件中的以下语句完成了相同的事情。但是,我无法为ListView重新编写该代码 CType(e.Row.Controls(0), WebControl).Attributes("disabled") = "true" 亚当斯,约翰·P T 试试看 在ListView的ItemCreated上,最好使用I

我想根据行中的其他数据禁用ListView的Select命令。例如,如果UserStatus是“T”,我想灰显Select超链接并阻止选择该行

我在GridView中通过RowCreated事件中的以下语句完成了相同的事情。但是,我无法为ListView重新编写该代码

CType(e.Row.Controls(0), WebControl).Attributes("disabled") = "true"


亚当斯,约翰·P
T
试试看


在ListView的
ItemCreated

上,最好使用ItemDataBound事件并执行FindControl(“btnEdit”),只需设置Enabled属性


如何使用事件。

在项目模板中,可以使用数据绑定语法禁用按钮

<ItemTemplate>
    <asp:LinkButton id="btnEdit" runat="server" text="Select" 
                  Enabled=<%# Eval("UserStatus") == "T" %> />
</ItemTemplate>


e.row未被识别为ListView的网络控件。我试过e.Item和LiteralControl,但运气不好。谢谢。虽然我使用了上面gbs的答案,但我确信数据绑定语法也可以工作。我挂断了ItemCreated事件,因为它对GridView有效。
<tr id="ListView_rowUsers_0">
  <td><a id="ListView_btnEdit_0" href="javascript:__doPostBack('ListView$ctrl0$btnEdit','')">Select</a></td>
  <td><span id="ListView_UserNameLabel_0">Adams,John P</span></td>
  <td><span id="ListView_UserStatusLabel_0">T</span></td>
</tr>
CType(e.Item.Controls(0), WebControl).Attributes("disabled") = "disabled"
<ItemTemplate>
    <asp:LinkButton id="btnEdit" runat="server" text="Select" 
                  Enabled=<%# Eval("UserStatus") == "T" %> />
</ItemTemplate>