Hi,
I'm trying to figure out how to add an extra row to my dataset so that I can bind to a repeater. I'm querying SQL for a list of records based on a Zip Code search. A function that I have returns a value called 'Distance'. I need this to appear next to the listings.
My Code is here:
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' ----------- STEP 1: GET LONGITUDE AND LATITUDE OF THE USER'S PROVIDED ZIP CODE -----------
Dim DBConnection As SqlConnection
Dim DBAdapter As SqlDataAdapter
Dim DBDataSet As DataSet
Dim SQLString As String
DBConnection = New SqlConnection(Configuratio
nManager.A
ppSettings
("apdtConn
ect2"))
SQLString = "SELECT Latitude, Longitude FROM ZIPCodes WHERE ZIPCode = '92352'"
DBAdapter = New SqlDataAdapter(SQLString, DBConnection)
DBDataSet = New DataSet
DBAdapter.Fill(DBDataSet, "ZIPCodes")
Dim Latitude As Double = DBDataSet.Tables("ZIPCodes
").Rows(0)
("Latitude
")
Dim Longitude As Double = DBDataSet.Tables("ZIPCodes
").Rows(0)
("Longitud
e")
lblLatitude.Text = Latitude
lblLongitude.Text = Longitude
' ----------- STEP 2: GET LIST OF TRAINERS THAT MATCH ZIP CODE -----------
' Check to see if any records exist
Dim ZIPExists As Boolean = Not (DBDataSet.Tables("ZIPCode
s") Is Nothing)
If ZIPExists Then
' Trainers exist, get info about trainers
Dim Miles As Double = 25
Dim zcdRadius As New ZIPCodeDownload.RadiusAssi
stant(Lati
tude, Longitude, Miles)
SQLString = "" _
& " SELECT * FROM vwTrainerSearchUSRev WHERE" _
& " Latitude >= " & zcdRadius.MinLatitude _
& " AND Latitude <= " & zcdRadius.MaxLatitude _
& " AND Longitude >= " & zcdRadius.MinLongitude _
& " AND Longitude <= " & zcdRadius.MaxLongitude _
& " AND CityType = 'D'"
DBAdapter.SelectCommand.Co
mmandText = SQLString
DBAdapter.Fill(DBDataSet, "ZipCodeOutput")
Dim zcdDistance As New ZIPCodeDownload.DistanceAs
sistant()
Dim thisRow As System.Data.DataRow
DBDataSet.Tables("ZipCodeO
utput").Co
lumns.Add(
"ShowMiles
")
For Each thisRow In DBDataSet.Tables("ZipCodeO
utput").Ro
ws
Dim Latitude2 As Double = CDbl(thisRow("Latitude"))
Dim Longitude2 As Double = CDbl(thisRow("Longitude"))
Dim Distance As Double = zcdDistance.Distance(Latit
ude, Longitude, Latitude2, Longitude2)
' THIS IS WHAT RETURNS THE 'DISTANCE' VALUE. THIS GIVES THE MILES. I need it to be added to the repeater output on the page.
If Distance <= Miles Then
' Trainer is within distance, so process the info here
DBDataSet.Tables("ZipCodeO
utput").Ro
ws(2)("Sho
wMiles") = Distance
Repeater1.DataSource = DBDataSet.Tables("ZipCodeO
utput")
Repeater1.DataBind()
Else
' Trainer is further than the preference, so do nothing.
End If
Next
Else ' Else statement on If ZIPExists
' No trainers exist, therefore do nothing
End If ' End Sub If ZIPExists
End Sub ' End Sub Page Load
</script>
AND ON THE PAGE...
<form id="form1" runat="server">
<asp:Label ID="lblLatitude" runat="server"></asp:Label
> and <asp:Label ID="lblLongitude" runat="server"></asp:Label
>
<br />
<br />
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%#DataBinder.Eval(Contain
er, "DataItem.City")%> <%#DataBinder.Eval(Contain
er, "DataItem.ShowMiles")%>
<br />
</ItemTemplate>
</asp:Repeater>
</form>
Working page of output results is here:
http://dev.apdt.com/po/ts/test4.aspx Basically, i just need to have this list sorted by DISTANCE from shortest to farthest, with the distance displaying NEXT TO EACH CITY.
Much thanks in advance for any advice!
Sincerely,
Chris
Start Free Trial