C# 如果读取器对象不为null,则返回true,否则返回false

C# 如果读取器对象不为null,则返回true,否则返回false,c#,asp.net,.net,c#-4.0,c#-3.0,C#,Asp.net,.net,C# 4.0,C# 3.0,我使用DataList显示数据库中的一些数据,并填充html端的字段。我现在需要根据db字段是否包含数据来更改面板的可见性 我需要能够显示面板,如果相关的数据字段有内容,并隐藏它,如果它没有。例如: <asp:Panel ID="pnlNew" runat="server" Style="margin:0; padding:0; width:42px; height:18px; bottom:5px; right:10px; float:right; position:relati

我使用DataList显示数据库中的一些数据,并填充html端的字段。我现在需要根据db字段是否包含数据来更改面板的可见性

我需要能够显示面板,如果相关的数据字段有内容,并隐藏它,如果它没有。例如:

    <asp:Panel ID="pnlNew" runat="server" Style="margin:0; padding:0; width:42px; height:18px; bottom:5px; right:10px; float:right; position:relative; background:url(../_imgVideoBadge.png) no-repeat;" Visible='<%# Eval("cheese") != null %>' ToolTip="available"></asp:Panel>
如何将其应用于上述要求


提前感谢。

这是我设法找到的解决方案:

protected void Page_Load(object sender, EventArgs e)
   {
      if (!Page.IsPostBack)          
        SqlConnection MyConnection;
        SqlCommand MyCommand;
        SqlDataReader MyReader;
        MyConnection = new SqlConnection();
        MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings["AppConnectionString1"].ConnectionString;

        MyCommand = new SqlCommand();
        MyCommand.CommandText = "SELECT TOP 10 * From PRODUCTS";
        MyCommand.CommandType = CommandType.Text;
        MyCommand.Connection = MyConnection;

        MyCommand.Connection.Open();
        MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection);
        if (MyReader != null)
        {
            datalist1.DataSource = MyReader;
            datalist1.DataBind();
            pnlNew.Visible = true;
        }
        else
        {
            pnlNew.Visible = false;
        }
        MyCommand.Dispose();
        MyConnection.Dispose();
    }
}
    (Eval("cheese").ToString().Trim() == String.Empty) ? false : true

结果似乎是一个空字符串而不是null。

Visible='
应该返回一个布尔值。

对不起。这真的不能回答问题。关键是要在html端这样做。好的,我们也会从html端试试。这就是代码隐藏!除非你很奇怪,否则你不会在html中这样做。谢谢你的回复,但是“信息”是什么?它是一个内置类,包含几个静态助手方法。有关更多详细信息,请参阅。
    (Eval("cheese").ToString().Trim() == String.Empty) ? false : true