Search code examples
asp.netrepeater

Display fields depend on user role


i have a page that shows products and each product has 2 price one for regular customers and one for cooperation that is cheaper and i want to show second price for users that are in "Cooperation" role and show first price for other users. i am using repeater and in repeater i used

<%# Eval("UnitPrice") %>

now i want to use

<%# Eval("CooperationPrice") %>

if user role is "cooperation". something like this in c#

if(User.IsInRole("cooperation")){//show second price}else{//show first price}

Solution

  • You can use C# Conditional Operator like this:-

    <%# User.IsInRole("cooperation")) ? Eval("CooperationPrice") : Eval("UnitPrice") %>