SunQuest
 
           Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old February 9th, 2004, 12:52 PM
jps@dhs jps@dhs is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 1 jps@dhs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Why does this code break when I do anything with control?

I'm rather new with this (ASP - .net)
web stuff in general.

I have managed to get a page to load containing exactly what I want it to show in a dropdown and a datagrid. I do want to limit the number of rows shown on a page in the data grid to 15 or so and to be able to go page by page to the rest and also to have the query altered based on the selected value from the drop down. Everything appears to be fine until I select from the dropdown or try to go to the next page of data grid items. Then I get "Page not found"

What am I missing?

<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

' Insert page code here

Dim myC As New SqlConnection
Dim sIndex as Integer = 0
dim dv as dataview
Dim ds as DataTable



sub Page_load(sender as Object, e As EventArgs)
if not ispostback()

Dim Sql2Run as string
Dim adpReserves As SqlDataAdapter = new SqlDataAdapter()
Dim adpCenters As SqlDataAdapter = new SqlDataAdapter()
Dim ctrReader As SqlDataReader

' A table mapping tells the adapter what to call the table.
adpReserves.TableMappings.Add("Table", "Reserves")

myC.ConnectionString = "Server=DHS-SQL-03SVR;Database=ChangesODS;UID=ChangesODS;PWD=chang es;"
myC.open()



Sql2Run = loadcenters()


dim cmdCenters as new sqlCommand(Sql2RUn,myC)
ctrReader = cmdCenters.ExecuteReader()
'TextBox1.text = trim(TextBox1.text) & cstr(dscenters.rows.count)

While ctrReader.Read()
DropDownList1.Items.Add(new ListItem(ctrReader("Center")))
End While

ctrReader.close()

createTempTable()
loadtemptable()
Sql2Run = flattentable()

dim cmdReserves as new sqlCommand(sql2run,myC)
adpReserves.SelectCommand = cmdReserves
ds = New DataTable("Reserves")
adpReserves.Fill(ds)
Datagrid1.VirtualItemCount = ds.rows.count

dim dv as new dataview(ds)
Datagrid1.datasource = dv

Session("DataSet") = ds
Session("EditIdx") = -1

dim cmdTmpCmd as New SqlCommand("Drop Table #pivotthis", myC)
cmdTmpCmd.ExecuteNonQuery()
else

ds = Ctype(Session("DataSet"), DataTable )
dv = new DataView(ds)
Datagrid1.datasource = dv
datagrid1.EditItemIndex = Ctype(Session("EditIdx"), integer)
end if

bindgrid()

end sub

function createTempTable()

on error resume next

dim tempCmd as string


tempcmd = "Drop Table #pivotthis"
dim cmdTmpCmd as New SqlCommand(tempCmd, myC)
cmdTmpCmd.ExecuteNonQuery()



tempCmd = "create table #pivotthis( countof integer,Center varchar(40), " & _
"shelter varchar(40), " & _
"scheduleid varchar(40), " & _
"descr varchar(40), " & _
"attInteger integer);"
dim cmdTmpCmd2 as New SqlCommand(tempCmd, myC)
cmdTmpCmd2.ExecuteNonQuery()


end function


function loadcenters() as String

loadcenters = "select distinct i.provider 'Center' " & _
"from institutions i " & _
"where i.typeofprvd='700'"


End function





function loadtemptable()

dim sqlstr as string

sqlstr = "insert into #pivotthis " & _
"select distinct count(*), s.department,institutions.provider , schedules.scheduleid, schedules.servdescription," & _
"cast(attendance.createdate as integer) " & _
"from attendance,schedules,serviceinter,institutions,sta ff s," & _
"(select min(attendid) attendid " & _
"from attendance " & _
"where attendance.createdate between ('2003-07-01 00:00:00.000') and ('2003-12-31 23:59:59.000') " & _
"group by clientid,scheduleid,cast(attendance.createdate as integer)) tx " & _
"where attendance.createdate between ('2003-07-01 00:00:00.000') and ('2003-12-31 23:59:59.000') " & _
"and institutions.providerid=serviceinter.providerid " & _
"and tx.attendid = attendance.attendid " & _
"and attendance.scheduleid=schedules.scheduleid " & _
"and serviceinter.serviceid=schedules.serviceid " & _
"and institutions.providerid=serviceinter.providerid " & _
"and s.logonid = substring(attendance.attendid,1,10) " & _
"and institutions.provider in('A Man''s Place','A Woman''s Place','Dolores Street','Ella Hill Hutch', " & _
"'Episcopal Sanctuary','Hospitality House','Lark Inn Youth','MSC South','New Liberation'," & _
"'Next Door','Providence','St. Boniface','St. Paulus','Third Baptist') " & _
"group by s.department,institutions.provider , schedules.scheduleid, schedules.servdescription,cast(attendance.createda te as integer);"

dim cmdTmpCmd as New SqlCommand(sqlstr, myC)
cmdTmpCmd.ExecuteNonQuery()

end function


Function flattenTable() as string

Dim iAdd2Date As Integer
Dim caseDate As string
Dim gtStr As String
Dim ctr As Integer
Dim caseStr As String
Dim caselen As Long
Dim sqlstr as String
dim d1 as date
dim d2 as date
d1 = cdate("2003-11-30")
d2 = cdate("2003-12-31")
iAdd2Date = DateDiff("d", d1,d2) + 1

For ctr = 0 To iAdd2Date - 1
caseDate = CStr(DateAdd("d", ctr, d1))
caseStr = caseStr & "sum(case attInteger when cast(cast(convert(char(10),'" & caseDate & "',120) as datetime) as integer) " & _
" then countof else 0 end) as '" & caseDate & "', " & Chr(10)
gtStr = gtStr & "sum(case attInteger when cast(cast(convert(char(10),'" & caseDate & "',120) as datetime) as integer) " & _
" then countof else 0 end) + " & Chr(10)
Next

caselen = Len(RTrim(gtStr)) - 3
gtStr = Mid(gtStr, 1, caselen)
gtStr = gtStr & " as 'Section Total' "



flattentable = "select center 'Resource Center',shelter 'Shelter' ,descr 'Section', " & caseStr & " " & gtStr & " " & _
"from #pivotthis " & _
"group by center,shelter,descr,scheduleid " & _
"order by center,shelter,descr,scheduleid "


end function

Protected sub NewPage(sender as Object,e as DataGridPageChangedEventArgs)

datagrid1.CurrentPageIndex = e.NewPageIndex
BindGrid()

End Sub

sub BindGrid()
datagrid1.DataSource = ds
datagrid1.DataBind()
end sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p runat="server">
&nbsp;<asp:DropDownList id="DropDownList1" AutoPostBack="True" runat="server"></asp:DropDownList>
</p>
<p>
</p>
<p>
<asp:DataGrid id="DataGrid1" runat="server" GridLines="Both" PageSize="20" AllowPaging="True" PagerStyle-Mode="NumericPages" PagerStyle-HorizontalAlign="Right" PagerStyle-NextPageText="Next" PagerStyle-PrevPageText="Prev" OnPageIndexChanged="NewPage" BorderColor="Black" ItemStyle-BackColor="Yellow" AlternatingItemStyle-BackColor="White" Font-size="8pt" font-name="Arial Narrow Bold" Header-Font="Arial Black" HeaderForeColor="Yellow" gridlinecolor="Black" HeaderStyle-BackColor="#80FFFF" GridLineStyle="Solid" BorderStyle="Groove">
<HeaderStyle backcolor="#80FFFF"></HeaderStyle>
<PagerStyle nextpagetext="Next" prevpagetext="Prev" horizontalalign="Right" mode="NumericPages"></PagerStyle>
<AlternatingItemStyle font-names="Monospac821 BT" borderstyle="Groove" backcolor="BlanchedAlmond"></AlternatingItemStyle>
<ItemStyle backcolor="Yellow"></ItemStyle>
</asp:DataGrid>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<!-- Insert content here -->
</form>
</body>
</html>
:mad:

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Why does this code break when I do anything with control?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway