[Last Call] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2011-10-06
Medium Priority
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
  • 2
LVL 15

Expert Comment

ID: 36926535

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

guildernet earned 0 total points
ID: 36942187
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

ID: 36972668
Research on my own lead me to the solution.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

834 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