当会话值等于变量

时间:2015-11-16 14:54:23

标签: asp.net listview

当会话变量不等于2时,我想隐藏listview中的编辑按钮。当session等于2时,我希望编辑按钮可见。

我的代码如下。

<asp:ListView ID="ListView1" runat="server" DataKeyNames="UserStoryID" DataSourceID="ShowProjectsTest">
           <AlternatingItemTemplate>
                <tr style="">


                   <td>
                       <asp:Label ID="StoryLabel" runat="server" Text='<%# Eval("Story") %>' />
                   </td>
                   <td>
                       <asp:Label ID="EstimatedTimeLabel" runat="server" Text='<%# Eval("EstimatedTime") %>'  />
                   </td>

                   <td>
                       <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" Font-Size="Small" />
                       <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" Font-Size="Small" />
                   </td>

                       <asp:Label ID="UserStoryIDLabel" runat="server" Text='<%# Eval("UserStoryID") %>' Visible="false" />
                       <asp:Label ID="ProjectIDLabel" runat="server" Text='<%# Eval("ProjectID") %>' Visible="false" />
                       <asp:Label ID="SprintIDLabel" runat="server" Text='<%# Eval("SprintID") %>' Visible="false" />



               </tr>
           </AlternatingItemTemplate>

       </asp:ListView>

1 个答案:

答案 0 :(得分:0)

将Visible属性添加到编辑按钮,然后在后面的代码中切换它。

Mark Up:

<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" Font-Size="Small" Visible="false" />

代码背后:

this.EditButton.Visible = (Session["Key"] as int) == 2;