ListView Edit Button Visibility

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanndeb
    New Member
    • May 2010
    • 33

    #1

    ListView Edit Button Visibility

    Hi i have a listview and i want the edit button in the itemtemplate to be visible if two conditions are satisfied

    1. The User Must Be A Manager
    2. A Column Named "IsActive" In That Row Must Be True...

    Now I Can Do Like...

    Code:
    <asp:ListView runat="server" ID="lstGrInfo"
    ........
    <ItemTemplate>
    ........
    <tr>
    <td>
    <asp:LinkButton ID="EditButton" runat="server" Text="Edit" CommandName="Edit" 
        Visible='<%#Bind("IsActive")%>'/>
    </td>
    .....
    </tr>
    </ItemTemplate>
    ......
    </asp:ListView>
    To check against the column value....

    Or

    Code:
    <asp:ListView runat="server" ID="lstGrInfo"
    ........
    <ItemTemplate>
    ........
    <tr>
    <td>
    <asp:LinkButton ID="EditButton" runat="server" Text="Edit" CommandName="Edit" 
        Visible='IsManager(<%=User.Identity.Name%>)'/>
    </td>
    .....
    </tr>
    </ItemTemplate>
    ......
    </asp:ListView>
    To check manager against the method in code behind called "IsManager(stri ng id)"

    But i can't marge them i.e if both conditions are satisfied then the edit button will be visible... say like...
    Code:
    Visible='IsManager(<%=User.Identity.Name%>) && <%#Bind("IsActive")%>'
    Or something like that...

    How do i do that?

    Thanks in advance....
  • sanndeb
    New Member
    • May 2010
    • 33

    #2
    Originally posted by sanndeb
    Hi i have a listview and i want the edit button in the itemtemplate to be visible if two conditions are satisfied

    1. The User Must Be A Manager
    2. A Column Named "IsActive" In That Row Must Be True...

    Now I Can Do Like...

    Code:
    <asp:ListView runat="server" ID="lstGrInfo"
    ........
    <ItemTemplate>
    ........
    <tr>
    <td>
    <asp:LinkButton ID="EditButton" runat="server" Text="Edit" CommandName="Edit" 
        Visible='<%#Bind("IsActive")%>'/>
    </td>
    .....
    </tr>
    </ItemTemplate>
    ......
    </asp:ListView>
    To check against the column value....

    Or

    Code:
    <asp:ListView runat="server" ID="lstGrInfo"
    ........
    <ItemTemplate>
    ........
    <tr>
    <td>
    <asp:LinkButton ID="EditButton" runat="server" Text="Edit" CommandName="Edit" 
        Visible='IsManager(<%=User.Identity.Name%>)'/>
    </td>
    .....
    </tr>
    </ItemTemplate>
    ......
    </asp:ListView>
    To check manager against the method in code behind called "IsManager(stri ng id)"

    But i can't marge them i.e if both conditions are satisfied then the edit button will be visible... say like...
    Code:
    Visible='IsManager(<%=User.Identity.Name%>) && <%#Bind("IsActive")%>'
    Or something like that...

    How do i do that?

    Thanks in advance....
    Ok I Got It Worked....

    Code:
    Visible='<%#isVisible(Eval("IsActive"), Convert.ToInt16(User.Identity.Name))%>'
    and in code behind...

    public bool isVisible(objec t isActive, short id)
    {
    //your logic goes here to return true or false....
    }

    Comment

    Working...