Paging through one record at a time

  • Thread starter Thread starter SouthSpawn
  • Start date Start date
S

SouthSpawn

Hello,

I have an asp.net application that will use a SQL Server DBMS for the
backend.
On my asp.net form. I have a next, previous, last and first buttons on my
form.
Basically, this application will allow the user to page through some data
one record at a time.

Let's say my SQL statement returns the following rows with ID's of (1, 3,
5, 9, 10).
What would be the best way that I can always retrieve the previousID and
nextID according to the rows my Select SQL statement returned?

Thanks,
Mark
 
You wouldn't care about the primary key while paging, you would only care
about the current record position.

an example in the winforms world would be (Thanks to Cor Ligthert)
http://www.windowsformsdatagridhelp.com/default.aspx?ID=c4832a2a-2b95-4ded-93d9-4deb7fa4a0b8

Notice here that on the button click events, he is moving forward or
backwards with in the datatable one row at a time.

The question you have to ask in the web world is where will the datatable
live that the user is browsing through?

If the datable remains on the webserver (possibly in a session variable)
then there will be a round trip to the server with ever button click.

<%

sub Load()

if not postback then

else
'Check for changes in the row the user was just looking at
'now move to the next location
GetRequest()
end if

end Sub

sub GetRequest()
Dim MemoryTable as datatable
Dim iDirection as integer
dim iPos as integer

iDirection = request("iDirection")

iPos = session("iPos")

select case iDirection
case "1"
iPos = iPos + 1
case "-1"
iPos = iPos - 1
end select

session("iPos") = iPos

MemoryTable = session("MemoryTable")
'Logic to change binding context

End Sub

%>



If the datatable remains with the browser client (possibly in the form of an
array of structures) then there is no round trip.


<script>
var iPos;
var MyData;
function moveforward()
{
iPos++;
bindcontrols();
}
function moveprevious()
{
iPos--;
bindcontrols
}

function bindcontrols()
{
try
{
document.forms[0].textbox1[0].value = MyData[iPos][0]
}
catch
{
alert("You're doing it wrong");
}
}

</script>
 
Back
Top