Link to home
Start Free TrialLog in
Avatar of guildernet
guildernetFlag for United States of America

asked on

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

Avatar of Navneet Hegde
Navneet Hegde
Flag of United States of America image

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!
ASKER CERTIFIED SOLUTION
Avatar of guildernet
guildernet
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of guildernet

ASKER

Research on my own lead me to the solution.