Using Visual Studio 2010 and VB.Net to build simple page

Posted on 2011-10-06
Last Modified: 2012-06-22
Ok, I have a simple classic asp page that creates a record set then, if there are no records found it writes out a table with a message saying "No Alerts Found for Texas".

If there are records found, it then creates a Table wtih the location header and spits out the records in rows below it.

This works fine in my classic asp form. However, im' having trouble in Visual Studio ASP.NET VB.

In ASP.NET I came close by creating a SQLDataSource and then formatted a DataList to display the records the way I want. The problem I have is I cant find a way to do what I need.  What I want to do is check if the there are no records. If so, then I want to only the Lable I have below the DataList. If there are records then I want to display the DataList and not the label.

By default it looks like Datalists write the header automatically and nothing below it if the datalist is empty. If the data list is empty I dont want it to write the datalist at all, just the label I have below that says "No Records Found".

I have attached my Classic ASP Code to see if anyone who is good with ASP VB.NET can tell me how I should approach this. I'm typically a Dreamweaver person who is makign the switch to Visual Studio 2010.

Thanks, Steff
Dim RsTexasAlert
Dim RsTexasAlert_cmd
Dim RsTexasAlert_numRows

Set RsTexasAlert_cmd = Server.CreateObject ("ADODB.Command")
RsTexasAlert_cmd.ActiveConnection = MM_EmployeeSite_STRING
RsTexasAlert_cmd.CommandText = "SELECT * FROM dbo.sqryEEICAdminView WHERE EEICLocationID = 4 ORDER BY SortDate asc" 
RsTexasAlert_cmd.Prepared = true

Set RsTexasAlert = RsTexasAlert_cmd.Execute
RsTexasAlert_numRows = 0

Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
RsTexasAlert_numRows = RsTexasAlert_numRows + Repeat1__numRows

' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

Dim MM_keepNone
Dim MM_keepURL
Dim MM_keepForm
Dim MM_keepBoth

Dim MM_removeList
Dim MM_item
Dim MM_nextItem

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then
  MM_removeList = MM_removeList & "&" & MM_paramName & "="
End If


' add the URL parameters to the MM_keepURL string
For Each MM_item In Request.QueryString
  MM_nextItem = "&" & MM_item & "="
  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
    MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item))
  End If

' add the Form variables to the MM_keepForm string
For Each MM_item In Request.Form
  MM_nextItem = "&" & MM_item & "="
  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
    MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item))
  End If

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
If (MM_keepBoth <> "") Then 
  MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
End If
If (MM_keepURL <> "")  Then
  MM_keepURL  = Right(MM_keepURL, Len(MM_keepURL) - 1)
End If
If (MM_keepForm <> "") Then
  MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
End If

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
  If (firstItem <> "") Then
    MM_joinChar = "&"
    MM_joinChar = ""
  End If
End Function


 <% If Not RsTexasAlert.EOF Or Not RsTexasAlert.BOF Then %>
        <table width="750" border="0" align="center" cellpadding="2" cellspacing="2">
            <td bgcolor="#184CB1"><div align="center"><span class="style2">Alerts for Freeport Texas</span></div></td>
        <% End If ' end Not RsTexasAlert.EOF Or NOT RsTexasAlert.BOF %>
While ((Repeat1__numRows <> 0) AND (NOT RsTexasAlert.EOF)) 
<% If Not RsTexasAlert.EOF Or Not RsTexasAlert.BOF Then %>
            <table width="750" border="0" align="center" cellpadding="2" cellspacing="2">
              <tr bgcolor="<%
If (Repeat1__numRows Mod 2) Then
End IF
                <td><img src="<%=(RsTexasAlert.Fields.Item("EventTypeImage").Value)%>" align="absmiddle" />&nbsp;<span class="style4">** <%=(RsTexasAlert.Fields.Item("EventTypeTxt").Value)%> **</span>&nbsp; <span class="style3">&nbsp;&nbsp;<a href="articledetails.asp?<%= Server.HTMLEncode(MM_keepForm) & MM_joinChar(MM_keepForm) & "ArticleID=" & RsTexasAlert.Fields.Item("ArticleID").Value %>"><%=(RsTexasAlert.Fields.Item("ArticleTitle").Value)%></a>&nbsp;&nbsp;<strong>posted</strong>&nbsp;<%=(RsTexasAlert.Fields.Item("DatePosted").Value)%></span></td>
            <% End If ' end Not RsTexasAlert.EOF Or NOT RsTexasAlert.BOF %>
      <% If RsTexasAlert.EOF And RsTexasAlert.BOF Then %>
  <table width="750" border="0" align="center" cellpadding="2" cellspacing="2">
      <td><div align="center">** Currently there are no Alerts for Freeport Texas **</div></td>
  <% End If ' end RsTexasAlert.EOF And RsTexasAlert.BOF %>
<BR /><BR />


Open in new window

Question by:guildernet
    LVL 15

    Expert Comment


    First thing
    ASP and ASP.Net - Sould is the same, but Body changed.

    You have to Use DataTable instead of  Recordset using SQLCommand instead of  ADODB.Command
    in short Change ADO to ADO.Net
    this all goes to the Code-behind Page  (.cs)
     Here is the Link

    For the Aspx Page changes, though things can be attained in better way using server control.
    But you can however have same approach as in Classic ASP

    This is how you can do
    <table border="0"> 
        <% For Each col As DataColumn In Model.Columns %> 
        <th><%= col.ColumnName %> 
        <% Next %> 
      <% For Each row as DataRow In Model.Rows %> 
        <% For Each col  as DataColumn In Model.Columns %> 
        <td><%= row(col).ToString() %></td> 
        <% Next %> 
      <% Next %> 

    Open in new window

    You should do a basic learning of .Net though.


    Accepted Solution

    The solution actually ends up being the following.

    Create a SQLData Source that connects to the table, or view that contains the data that you need.

    Then, use the ListView Server control to return the data to the page. Once you have the correct data showing up on the page, I hand tweaked it to display in a table structure that I wanted. It works great.

    In ListView Server control there is an option for what to display if there are no records to return. I put my custom CSS and Message in between those tags and it works like a charm.

    Author Closing Comment

    Research on my own lead me to the solution.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now