Default Paging

J

Jeff Thur

Here is my problem:

I have created a Database Lookup program for users to
search the SQL Database for specific records. The program
uses a SQL Stored Procedure with variables that the user
plugs in. After the values are plugged in, they then
click a button to submit their query. I have searched
numerous articles on default paging, but I have only
found articles that run a query with in the code with
standard values and not variables. This is easy, since
the Databind Method is called from the Page_Load method
and an event handler handles the paging. I have fooled
around with trying to get the paging correct using the
paramaterized Stored Procedure but have had no luck at
all. The program works fine with no paging. I am copying
the program here to look at. Would appreciate any kind of
help that anybody can give.

Thanks........


Sub Page_Load(Sender As Object, e As EventArgs)

IF Not Page.IsPostback Then
State.Items.Add ("")
State.Items.Add ("AL")
State.Items.Add ("AK")
State.Items.Add ("AZ")
State.Items.Add ("AR")
State.Items.Add ("CA")
State.Items.Add ("CO")
State.Items.Add ("CT")
State.Items.Add ("DC")
State.Items.Add ("DE")
State.Items.Add ("FL")
State.Items.Add ("GA")
State.Items.Add ("HI")
State.Items.Add ("ID")
State.Items.Add ("IL")
State.Items.Add ("IN")
State.Items.Add ("IA")
State.Items.Add ("KS")
State.Items.Add ("KY")
State.Items.Add ("LA")
State.Items.Add ("ME")
State.Items.Add ("MA")
State.Items.Add ("MD")
State.Items.Add ("MI")
State.Items.Add ("MN")
State.Items.Add ("MO")
State.Items.Add ("MS")
State.Items.Add ("MT")
State.Items.Add ("NE")
State.Items.Add ("NV")
State.Items.Add ("NH")
State.Items.Add ("NJ")
State.Items.Add ("NM")
State.Items.Add ("NY")
State.Items.Add ("NC")
State.Items.Add ("ND")
State.Items.Add ("OH")
State.Items.Add ("OK")
State.Items.Add ("OR")
State.Items.Add ("PA")
State.Items.Add ("RI")
State.Items.Add ("SC")
State.Items.Add ("SD")
State.Items.Add ("TN")
State.Items.Add ("TX")
State.Items.Add ("UT")
State.Items.Add ("VT")
State.Items.Add ("VA")
State.Items.Add ("WA")
State.Items.Add ("WV")
State.Items.Add ("WI")
State.Items.Add ("WY")
End If



End Sub

Sub Button1_Click(sender As Object, e As EventArgs)

BindData()

End Sub



Sub BindData
Dim DS As DataSet



Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New SqlConnection
("server='(local)'; user id='sa'; password='fritz';
database='Cutis'")
MyCommand = New SqlDataAdapter("EMSLKUPS",
MyConnection)
MyCommand.SelectCommand.CommandType =
CommandType.StoredProcedure
MyCommand.SelectCommand.Parameters.Add(New
SqlParameter("@TxtFirst", SqlDbType.NVarChar, 1))
MyCommand.SelectCommand.Parameters
("@TxtFirst").Value = TxtFirst.Text
MyCommand.SelectCommand.Parameters.Add(New
SqlParameter("@TxtLast", SqlDbType.NVarChar, 6))
MyCommand.SelectCommand.Parameters
("@TxtLast").Value = TxtLast.Text
MyCommand.SelectCommand.Parameters.Add(New
SqlParameter("@TxtState", SqlDbType.NVarChar, 2))
MyCommand.SelectCommand.Parameters
("@TxtState").Value = State.SelectedValue
MyCommand.SelectCommand.Parameters.Add(New
SqlParameter("@TxtSubscr", SqlDbType.NVarChar, 10))
MyCommand.SelectCommand.Parameters
("@TxtSubscr").Value = TxtSubscr.Text




DS = new DataSet()
MyCommand.Fill(DS, "Results")

DataGrid1.DataSource=DS.Tables("Results").DefaultView
DataGrid1.DataBind()



TxtLast.Text =""
TxtFirst.Text =""
TxtSubscr.Text =""

myconnection.Close()
End Sub


Sub DataGrid1_PageChanger(sender As Object, e As
DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = E.NewPageIndex
' Set the CurrentPageIndex before binding the grid
BindData()
End Sub
 
E

Elton Wang

Try

DataGrid1.CurrentPageIndex = E.NewPageIndex
DataGrid1.DataBind()

In DataGrid1_PageChanger

rather than

DataGrid1.CurrentPageIndex = E.NewPageIndex
BindData()

HTH

Elton Wang
 
J

Jeff Thur

-----Original Message-----
Try

DataGrid1.CurrentPageIndex = E.NewPageIndex
DataGrid1.DataBind()

In DataGrid1_PageChanger

rather than

DataGrid1.CurrentPageIndex = E.NewPageIndex
BindData()

HTH

Elton Wang



.
Hi Elton, Still no luck with the change I made. When I
go to next page, the page is blank. Any other ideas.

Jeff............
 
E

Elton Wang

What is viewstate of the datagrid, enabled or disabled?

If it's disabled, it's better to enable it.
 
G

Guest

-----Original Message-----
What is viewstate of the datagrid, enabled or disabled?

If it's disabled, it's better to enable it.


.
Hi Elton.

The View State Was Enabled Still No Luck Though.

Jeff..............
 
G

Guest

-----Original Message-----
Could you post more details about your code, HTML and
codebehind?

Elton

I have a screen.

The Screen has a textbox where the user provides a first
intial of a first name.
Another textbox where the user provides the first 6
characters of a last name.
A Third textbox where the user supplies a subscriber
number.
A drop down box is also included which contains all the
States.

The user can supply all fields, just one field and any
combination of fields. A SQL Stored Procedure named
EMSLKUPS handles the selections.

Once the user enters his parameters, he clicks on a
button named Submit Query.

Here is a breakdown of the code:

The Sub Page Load supplies the dropdown list of States,
but doesn't include any binding at all. I did try to do a
bind in here with both a PostBack and a non Postback.

Page_Load(Sender As Object, e As EventArgs)

IF Not Page.IsPostback Then
State.Items.Add ("")
State.Items.Add ("AL")
State.Items.Add ("AK")
State.Items.Add ("AZ")
State.Items.Add ("AR")
State.Items.Add ("CA")
State.Items.Add ("CO")
State.Items.Add ("CT")
State.Items.Add ("DC")
State.Items.Add ("DE")
State.Items.Add ("FL")
State.Items.Add ("GA")
State.Items.Add ("HI")
State.Items.Add ("ID")
State.Items.Add ("IL")
State.Items.Add ("IN")
State.Items.Add ("IA")
State.Items.Add ("KS")
State.Items.Add ("KY")
State.Items.Add ("LA")
State.Items.Add ("ME")
State.Items.Add ("MA")
State.Items.Add ("MD")
State.Items.Add ("MI")
State.Items.Add ("MN")
State.Items.Add ("MO")
State.Items.Add ("MS")
State.Items.Add ("MT")
State.Items.Add ("NE")
State.Items.Add ("NV")
State.Items.Add ("NH")
State.Items.Add ("NJ")
State.Items.Add ("NM")
State.Items.Add ("NY")
State.Items.Add ("NC")
State.Items.Add ("ND")
State.Items.Add ("OH")
State.Items.Add ("OK")
State.Items.Add ("OR")
State.Items.Add ("PA")
State.Items.Add ("RI")
State.Items.Add ("SC")
State.Items.Add ("SD")
State.Items.Add ("TN")
State.Items.Add ("TX")
State.Items.Add ("UT")
State.Items.Add ("VT")
State.Items.Add ("VA")
State.Items.Add ("WA")
State.Items.Add ("WV")
State.Items.Add ("WI")
State.Items.Add ("WY")
End If



End Sub


The Button Event is Clicked when the user enters his
search criteria. The Button Event then calls a method
with executes a Function.

Sub Button1_Click(sender As Object, e As EventArgs)
BindData()
End Sub


The following is the method which runs the SQL Stored
Procedure, Clears the input boxes and Binds to the
DataGrid.


Function BindData()
Dim DS As DataSet



Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New SqlConnection
("server='(local)'; user id='sa'; password='fritz';
database='Cutis'")

MyCommand = New SqlDataAdapter("EMSLKUPS",
MyConnection)

MyCommand.SelectCommand.CommandType =
CommandType.StoredProcedure

MyCommand.SelectCommand.Parameters.Add(New
SqlParameter("@TxtFirst", SqlDbType.NVarChar, 1))

MyCommand.SelectCommand.Parameters
("@TxtFirst").Value = TxtFirst.Text

MyCommand.SelectCommand.Parameters.Add(New
SqlParameter("@TxtLast", SqlDbType.NVarChar, 6))

MyCommand.SelectCommand.Parameters
("@TxtLast").Value = TxtLast.Text

MyCommand.SelectCommand.Parameters.Add(New
SqlParameter("@TxtState", SqlDbType.NVarChar, 2))

MyCommand.SelectCommand.Parameters
("@TxtState").Value = State.SelectedValue

MyCommand.SelectCommand.Parameters.Add(New
SqlParameter("@TxtSubscr", SqlDbType.NVarChar, 10))

MyCommand.SelectCommand.Parameters
("@TxtSubscr").Value = TxtSubscr.Text





DS = new DataSet()
MyCommand.Fill(DS, "Results")

DataGrid1.DataSource=DS.Tables("Results").DefaultView
DataGrid1.DataBind()



TxtLast.Text =""
TxtFirst.Text =""
TxtSubscr.Text =""

myconnection.Close()
End Function

Next the OnPageIndexChanged Event is fired.
Sub DataGrid1_PageChanger(sender As Object, e As
DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = E.NewPageIndex
DataGrid1.DataBind()
End Sub


Next I provide all the rest of the backround code.

<%@ Page Language="vb" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Web.Security " %>
<%@ import Namespace="System.Web.UI.WebControls" %>
<script runat="server">

In here is the body of the Program.................


</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
&nbsp;&nbsp;<asp:Label id="Label4"
runat="server" width="451px" forecolor="Green"
backcolor="#FFFFC0" borderstyle="Double" height="75px"
font-size="Large" font-bold="True">EPSILON
MANAGEMENT SYSTEMS **** LOOKUP SCREEN
****</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label
id="Label6" runat="server" width="71px" forecolor="Green"
backcolor="#FFFFC0" borderstyle="Double" height="76px"
font-size="XX-Large" font-bold="True" bordercolor="Green"
font-names="Arial
Black">EMS</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;
</p>
<p>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs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px"
bordercolor="Green">First
Initial of
FirstName</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox
id="TxtFirst" runat="server" Width="34px"
BorderStyle="Double" BorderColor="Green"
BackColor="#FFFFC0" ForeColor="Green"></asp:TextBox>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<p>
&nbsp;<asp:Label id="Label5" runat="server"
width="178px" forecolor="Green" backcolor="#FFFFC0"
borderstyle="Double">Subscriber

No.</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox
id="TxtSubscr" runat="server" BorderStyle="Double"
BorderColor="Green" BackColor="#FFFFC0"
ForeColor="Green"></asp:TextBox>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<p>
&nbsp;<asp:Label id="Label2" runat="server"
width="203px" forecolor="Green" backcolor="#FFFFC0"
borderstyle="Double" height="23px"
bordercolor="Green">First
6 chars of
LastName</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox
id="TxtLast" runat="server" Width="44px"
BorderStyle="Double" BorderColor="Green"
BackColor="#FFFFC0" ForeColor="Green"></asp:TextBox>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<p>
&nbsp;<asp:Label id="Label3" runat="server"
width="77px" forecolor="Green" backcolor="#FFFFC0"
borderstyle="Double"
bordercolor="Green">State</asp:Label>&nbsp;&nbsp;&nbsp;&nb
sp;<asp:DropDownList id="State" runat="server"
BackColor="#FFFFC0" ForeColor="Green"></asp:DropDownList>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<p>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<p>
</p>
<p>
&nbsp;<asp:HyperLink id="HyperLink2"
runat="server" Width="134px" BorderStyle="Double"
BorderColor="Green" BackColor="#FFFFC0" ForeColor="Green"
NavigateUrl="http://www.epsilonmail.com:8082/Baldwin99.asp
x">Run Another Query</asp:HyperLink>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button id="Button1"
onclick="Button1_Click" runat="server"
BorderStyle="Double" BackColor="#FFFFC0"
ForeColor="Green" Text="Submit Query"></asp:Button>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<p>
&nbsp;<asp:HyperLink id="HyperLink1"
runat="server" Width="121px" BorderStyle="Double"
BorderColor="Green" BackColor="#FFFFC0" ForeColor="Green"
NavigateUrl="http://www.epsilonmail.com:8082/default.aspx"
Home Page</asp:HyperLink>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:DataGrid
id="DataGrid1" runat="server" BorderStyle="Double"
BorderColor="Green" BackColor="#FFFFC0" ForeColor="Green"
OnPageIndexChanged="DataGrid1_PageChanger" PageSize="8"
AllowPaging="True" ShowFooter="True">
<EditItemStyle forecolor="Green"
backcolor="#FFFFC0"></EditItemStyle>
<AlternatingItemStyle forecolor="Green"
bordercolor="White"
backcolor="White"></AlternatingItemStyle>
</asp:DataGrid>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<!-- Insert content here -->
</form>
</body>
</html>
 
E

Elton Wang

Hi Jeff,

Sorry my mistake. You should use

DataGrid1.CurrentPageIndex = e.NewPageIndex
Re-Bind Datasource

I mean after resetting page index, you need re-bind data
source.

However, I notice when calling BindData() from
PageIndexChanged, you have reset some parameters. In the
first call, it takes TxtFirst.Text, TxtLast.Text, and
TxtSubscr.Text. And in the end of BindData(), you set them
to "". Hence when it is called from PageIndexChanged the
sp result is different from the first call.

Solution:
In BindData() method append following statements

' save data to session
Session("datagridData") = DS.Tables("Results").DefaultView

And in On PageIndexChanged

DataGrid1.CurrentPageIndex = e.NewPageIndex
' get data from session and cast to dataview
DataGrid1. DataSource = CType(Session("datagridData",
DataView))
DataGrid1.DataBind()

HTH

Elton
 
G

Guest

Hi Elton.

I made the changes suggested but when running the
application I get a runtime error. The changed code looks
as follows:

DS = new DataSet()
MyCommand.Fill(DS, "Results")
DataGrid1.DataSource=DS.Tables("Results").DefaultView
DataGrid1.DataBind()
' save data to session
Session("datagridData") = DS.Tables("Results").DefaultView

Am I doing something wrong?


Jeff....



myconnection.Close()
End Function


Sub DataGrid1_PageChanger(sender As Object, e As
DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = E.NewPageIndex
DataGrid1. DataSource = CType(Session("datagridData",
DataView))
DataGrid1.DataBind()
End Sub
 
J

Jeff Thur

-----Original Message-----
Hi Elton.

I made the changes suggested but when running the
application I get a runtime error. The changed code looks
as follows:

DS = new DataSet()
MyCommand.Fill(DS, "Results")
DataGrid1.DataSource=DS.Tables("Results").DefaultView
DataGrid1.DataBind()
' save data to session
Session("datagridData") = DS.Tables ("Results").DefaultView

Am I doing something wrong?

Here is the Stack Trace.
Line 126: Sub DataGrid1_PageChanger(sender As
Object, e As DataGridPageChangedEventArgs)
Line 127: DataGrid1.CurrentPageIndex = E.NewPageIndex
Line 128: DataGrid1. DataSource = CType(Session
("datagridData", DataView))
Line 129: DataGrid1.DataBind()
Line 130: End Sub


Source File: C:\Inetpub\Baldwin99.aspx Line: 128



Show Detailed Compiler Output:


C:\Inetpub> "C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607
\vbc.exe" /t:library /utf8output /R:"C:\WINDOWS\assembly\G
AC_MSIL\System.Web.Mobile\2.0.3600.0__b03f5f7f11d50a3a\Sys
tem.Web.Mobile.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\Syste
m.Xml\2.0.3600.0__b77a5c561934e089
\System.Xml.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.W
eb.Services\2.0.3600.0__b03f5f7f11d50a3a\System.Web.Servic
es.dll" /R:"C:\WINDOWS\assembly\GAC_32
\System.Data\2.0.3600.0__b77a5c561934e089
\System.Data.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.
Drawing\2.0.3600.0__b03f5f7f11d50a3a\System.Drawing.dll" /
R:"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.3600.0__b77a5c5
61934e089\System.dll" /R:"C:\WINDOWS\assembly\GAC_32
\System.EnterpriseServices\2.0.3600.0__b03f5f7f11d50a3a\Sy
stem.EnterpriseServices.dll" /R:"C:\WINDOWS\assembly\GAC_M
SIL\System.Web\2.0.3600.0__b03f5f7f11d50a3a\System.Web.dll
" /out:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607
\Temporary ASP.NET Files\root\63c23331\bf623d27
\mhkkiulh.dll" /D:DEBUG=1 /debug+ /win32resource:"C:\WINDO
WS\Microsoft.NET\Framework\v2.0.40607\Temporary ASP.NET
Files\root\63c23331\bf623d27
\mhkkiulh.res" /define:_MYTYPE=\"Web\" /define:_MYPUBLIC=F
alse /imports:Microsoft.VisualBasic,System,System.Collecti
ons,System.Collections.Specialized,System.Configuration,Sy
stem.Text,System.Text.RegularExpressions,System.Web,System
..Web.Caching,System.Web.SessionState,System.Web.Security,S
ystem.Web.Profile,System.Web.UI,System.Web.UI.Imaging,Syst
em.Web.UI.WebControls,System.Web.UI.WebControls.WebParts,S
ystem.Web.UI.HtmlControls "C:\WINDOWS\Microsoft.NET\Frame
work\v2.0.40607\Temporary ASP.NET Files\root\63c23331
\bf623d27
\mhkkiulh.0.vb" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.4
0607\Temporary ASP.NET Files\root\63c23331\bf623d27
\mhkkiulh.1.vb"


Microsoft (R) Visual Basic .NET Compiler version
8.0.40607.42
for Microsoft (R) .NET Framework version 2.0.40607.42
Copyright (C) Microsoft Corporation 1987-2003. All rights
reserved.

C:\Inetpub\Baldwin99.aspx(77) : warning BC42021: Function
without an 'As' clause; return type of Object assumed.

Function BindData()
~~~~~~~~
C:\Inetpub\Baldwin99.aspx(123) : warning BC42105:
Function 'BindData' doesn't return a value on all code
paths. A null reference exception could occur at run time
when the result is used.

End Function
~~~~~~~~~~~~
C:\Inetpub\Baldwin99.aspx(128) : error
BC30108: 'DataView' is a type and cannot be used as an
expression.

DataGrid1. DataSource = CType(Session
("datagridData", DataView))

~~~~~~~~
C:\Inetpub\Baldwin99.aspx(128) : error BC30196: Comma
expected.

DataGrid1. DataSource = CType(Session
("datagridData", DataView))
 
E

Elton Wang

There is a space between DataGrid1. and DataSource = ...
It should be
DataGrid1.DataSource = CType(Session
("datagridData", DataView))

BTW, change

Function BindData()

....

End Function

To

Sub BindData()

....

End Sub

The method doesn't return any thing, so it's not a
function. It's Sub.

HTH

Elton Wang
 
G

Guest

-----Original Message-----
There is a space between DataGrid1. and DataSource = ...
It should be
DataGrid1.DataSource = CType(Session
("datagridData", DataView))

BTW, change

Function BindData()

....

End Function



Good Morning Elton,

Yes, I took out the space but now I am getting the
following Error:

Line 124: Sub DataGrid1_PageChanger(sender As
Object, e As DataGridPageChangedEventArgs)
Line 125: DataGrid1.CurrentPageIndex = E.NewPageIndex
Line 126: DataGrid1.DataSource = CType(Session
("datagridData", DataView))
Line 127:
Line 128:


Source File: D:\Data\Archive\Baldwin99.aspx Line: 126



Show Detailed Compiler Output:


D:\Data\Archive> "c:\winnt\microsoft.net\framework\v1.1.43
22
\vbc.exe" /t:library /utf8output /R:"c:\winnt\assembly\gac
\system.drawing\1.0.5000.0__b03f5f7f11d50a3a\system.drawin
g.dll" /R:"c:\winnt\assembly\gac\system.web.mobile\1.0.500
0.0__b03f5f7f11d50a3a\system.web.mobile.dll" /R:"c:\winnt\
assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089
\system.xml.dll" /R:"c:\winnt\assembly\gac\system.web.serv
ices\1.0.5000.0__b03f5f7f11d50a3a\system.web.services.dll"
/R:"c:\winnt\assembly\gac\system\1.0.5000.0__b77a5c561934
e089
\system.dll" /R:"c:\winnt\assembly\gac\system.web\1.0.5000
..0__b03f5f7f11d50a3a\system.web.dll" /R:"c:\winnt\assembly
\gac\system.enterpriseservices\1.0.5000.0__b03f5f7f11d50a3
a\system.enterpriseservices.dll" /R:"c:\winnt\assembly\gac
\system.data\1.0.5000.0__b77a5c561934e089
\system.data.dll" /out:"C:\WINNT\Microsoft.NET\Framework\v
1.1.4322\Temporary ASP.NET Files\root\4fe01892
\3e40d99a\5ezzokxb.dll" /D:DEBUG=1 /debug+ /win32resource:
"C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary
ASP.NET Files\root\4fe01892
\3e40d99a\5ezzokxb.res" "C:\WINNT\Microsoft.NET\Framework
\v1.1.4322\Temporary ASP.NET Files\root\4fe01892
\3e40d99a\5ezzokxb.0.vb"


Microsoft (R) Visual Basic .NET Compiler version
7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322.2032
Copyright (C) Microsoft Corporation 1987-2002. All rights
reserved.

D:\Data\Archive\Baldwin99.aspx(126) : error
BC30684: 'DataView' is a type and cannot be used as an
expression.

DataGrid1.DataSource = CType(Session("datagridData",
DataView))

~~~~~~~~
D:\Data\Archive\Baldwin99.aspx(126) : error BC30196:
Comma expected.

So I changed the code to look like this:

DS = new DataSet()
MyCommand.Fill(DS, "Results")
DataGrid1.DataSource=DS.Tables("Results").DefaultView
DataGrid1.DataBind()

Session("datagridData") = DS.Tables("Results").DefaultView



myconnection.Close()
End Sub

Sub DataGrid1_PageChanger(sender As Object, e As
DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = E.NewPageIndex
DataGrid1.DataSource = CType (Session("datagridData"),
Dataview)
End Sub

What happens is when I try to page forward the same page
is posted back(Same results). However if I run the query
again(The text fields have not been cleared) without
erasing the name(eg: Smith) the next page is displayed
and so on. Any thoughts on this one.

Thanks for your time, really appreciate it!!!!

Jeff..........


DataGrid1.DataSource = CType(Session("datagridData",
DataView))

~
 
E

Elton Wang

It should be

DataGrid1.DataSource = CType(Session("datagridData"),
DataView)

It means get object from SessionState (key
= "datagridData") and cast it to DataView type.

Or you can simply
DataGrid1.DataSource = Session("datagridData")


HTH

Elton
 
G

Guest

-----Original Message-----
It should be

DataGrid1.DataSource = CType(Session("datagridData"),
DataView)

It means get object from SessionState (key
= "datagridData") and cast it to DataView type.

Or you can simply
DataGrid1.DataSource = Session("datagridData")


HTH


Yes, But I don't understand why the Grid is not paging
forward. It just posts back the first page over and over.
Only way to advance it is if you execute the query again.
Then you get page 2 and so on. I'm soooo frustrated now.

Jeff.............
 
G

Guest

Elton, I finally got it, The problem was I didn't rebind
the Datagrid in the OnPageChanged Sub. Thanks so much for
your patience and your help. One more thing if you might
know.
How can I format a phone number that is in the following
format nnnnnnnnnn to display on the grid as nnn-nnn-nnnn.
Thanks again, Jeff..................
 
E

Elton Wang

Hi Jeff,

I'm glad you figure it out yourself.

There are several ways to format string.

Dim intPhone as integer = Integer.Parse(strPhone)
Dim formatedPhone as string = intPhone.ToString("###-###-
####")

But if the strPhone starts with 0, it will fail.

The simple one is

Dim formatedPhone = strPhone.SubString(0,3) + "-" +
strPhone.SubString(3,3) + "-" + strPhone.SubString(6,4)

HTH

Have a nice weekend.

Elton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top