Conditional Logic in ASP.net page

前端 未结 5 998
半阙折子戏
半阙折子戏 2020-12-03 18:46

I have some code that prints out databse values into a repeater control on an asp.net page. However, some of the values returned are null/blank - and this makes the result

5条回答
  •  攒了一身酷
    2020-12-03 19:02

    I suggest wrapping each key/value pair into custom control with 2 properties. This control will display itself only if value is not empty:

     <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ShowPair.ascx.cs" Inherits="MyWA.ShowPair" %>
    
    <% if (!string.IsNullOrEmpty(Value))
       { %>
    <%=Key %> : <%=Value %>
    <% } %> 
    

    And then put controls into repeater template:

    
         
            
            
            
         
        
    

提交回复
热议问题