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

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

MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""

' 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
Next

' 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
Next

' 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 = "&"
  Else
    MM_joinChar = ""
  End If
End Function
%>

<body>

 <% If Not RsTexasAlert.EOF Or Not RsTexasAlert.BOF Then %>
        <table width="750" border="0" align="center" cellpadding="2" cellspacing="2">
          <tr>
            <td bgcolor="#184CB1"><div align="center"><span class="style2">Alerts for Freeport Texas</span></div></td>
          </tr>
        </table>
        <% 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
	Response.Write("#E7E9E4")
Else
	Response.Write("")
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>
              </tr>
            </table>
            <% End If ' end Not RsTexasAlert.EOF Or NOT RsTexasAlert.BOF %>
      <% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  RsTexasAlert.MoveNext()
Wend
%>
      <% If RsTexasAlert.EOF And RsTexasAlert.BOF Then %>
  <table width="750" border="0" align="center" cellpadding="2" cellspacing="2">
    <tr>
      <td><div align="center">** Currently there are no Alerts for Freeport Texas **</div></td>
          </tr>
  </table>
  <% End If ' end RsTexasAlert.EOF And RsTexasAlert.BOF %>
<BR /><BR />

</body>

Open in new window

guildernetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NavneetSoftware EngineerCommented:
HI!

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
http://msdn.microsoft.com/en-us/library/dw70f090(v=vs.71).aspx


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"> 
  <tr> 
    <% For Each col As DataColumn In Model.Columns %> 
    <th><%= col.ColumnName %> 
    <% Next %> 
  </tr> 
  <% For Each row as DataRow In Model.Rows %> 
  <tr> 
    <% For Each col  as DataColumn In Model.Columns %> 
    <td><%= row(col).ToString() %></td> 
    <% Next %> 
  </tr> 
  <% Next %> 
</table>

Open in new window


You should do a basic learning of .Net though.

Thanks!
0
guildernetAuthor Commented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
guildernetAuthor Commented:
Research on my own lead me to the solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.