Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 28th, 2004, 03:15 AM
Authorized User
 
Join Date: May 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hide NULL records

Hi,

I have the following code in .aspx page

Code:
<ItemTemplate>
                    <% if i = 1 then
       i = 2
    else
    i = 1
    end if
    %>
                    <tr>
                        <td class="content<%=i.toString()%>">
                            <p>
                                <a href="EToolTrivia.aspx?topic_id=<%#Container.DataItem("topic_name")%>" class="toplink"><%#Container.DataItem("topic_name")%></a></p>
                        </td>
                        <td class="content<%=i.toString()%>">
                            <p>
                                <%#Container.DataItem("Last_Login")%>
                            </p>
                        </td>
                        <td class="content<%=i.toString()%>">
                            <p>
                                <%# DisplayValue(Container.dataitem)%>
                            </p>
                        </td>
                        <td class="content<%=i.toString()%>">
                            <p>
                                <a href="EQuiz.aspx" class="toplink"><%#Container.DataItem("Quiz_Status")%></a></p>
                        </td>
                        <td class="content<%=i.toString()%>">
                            <p>
                                <%#Container.DataItem("Quiz_Score")%>
                            </p>
                        </td>
                    </tr>
                </ItemTemplate>


I have the following code behind
Code:
Public Class EHomePage
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents customers As System.Web.UI.WebControls.Repeater

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region



    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub

Function DisplayValue(dataitem as object) 
if dataitem("time_spent") = "" then
return ""
else return (dataitem("time_spent")) & " min"
end if 
End Function

End Class

Now when I run my .aspx page, I get the following error


Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'DisplayValue' is not declared.

Source Error:



Line 117: <td class="content<%=i.toString()%>">
Line 118: <p>
Line 119: <%# DisplayValue(Container.dataitem)%>
Line 120: </p>
Line 121: </td>


Source File: http://localhost/ELearning/EHomePage.aspx Line: 119

How do I get the displayValue function to work?

Basically I am just trying to hide the records if they are null in my database. Is there any other way to do this?




 
Old May 28th, 2004, 12:15 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 336
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alyeng2000
Default

may be you forgot to add the field name to
 
Quote:
quote:<%# DisplayValue(Container.dataitem("FieldName"))%>


you could avoid null records either by check Sql query in where condition " where id is not null"
or avoid dbnull values by using the sql function
isnull(id,DefaultValueIfNull)

Ahmed Ali
Software Developer
 
Old May 29th, 2004, 12:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

u have 2 ways not retrive null values but using IsNull & ... on SqlServer
of working on ur porgram witch I suggest the first.
but for second I have a sampel for u.
Code:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<Script Runat="Server">
  void Page_Load( Object s, EventArgs e )
  {
    SqlConnection myConnection;
    SqlCommand myCommand;
    myConnection = new SqlConnection( "Server=Localhost;uid=sa;Database=Pubs" );
    myCommand = new SqlCommand( "Select title, notes From Titles", myConnection );
    myConnection.Open();
    myRepeater.DataSource = myCommand.ExecuteReader();
    myRepeater.DataBind();
    myConnection.Close();
  }

  String fixNulls( String theString )
  {
    if ( theString == "" ) 
      return "[NULL]";
    else
      return theString;
  }
</Script>

<html>
<head><title>Titles</title></head>
<body>
 
<form Runat="Server">
 
<asp:Repeater
  id="myRepeater"
  Runat="Server">
  <HeaderTemplate>
  <table border=1 cellspacing=0 cellpadding=5>
  </HeaderTemplate>
  <ItemTemplate>
  <tr>
    <td><%# fixNulls( DataBinder.Eval( Container.DataItem, "title" ).ToString() ) %></td>
    <td><%# fixNulls( DataBinder.Eval( Container.DataItem, "notes" ).ToString() ) %></td>
  </tr>
  </ItemTemplate>
  <AlternatingItemTemplate>
  <tr bgcolor="lightyellow">
    <td><%# fixNulls( DataBinder.Eval( Container.DataItem, "title" ).ToString() ) %></td>
    <td><%# fixNulls( DataBinder.Eval( Container.DataItem, "notes" ).ToString() ) %></td>
  </tr>
  </AlternatingItemTemplate>
  <FooterTemplate>
  </table>
  </FooterTemplate>
</asp:Repeater>
</form>

</body>
</html>
Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
limiting/hiding records w/null values louisvillelivin Crystal Reports 0 February 5th, 2007 10:43 AM
delete null records stealthdevil Access VBA 3 January 23rd, 2007 04:48 PM
problem in updating records & finding records naveed77 VB How-To 1 January 16th, 2007 12:10 PM
How to set Not Null constraint to Null Columns arasu Oracle 1 August 22nd, 2005 10:09 AM
don't hide null fields in XML bmains SQL Server 2000 1 March 9th, 2004 04:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.