Search Tools Links Login

Create your own Grid


The code in here is an example of how you can display and manipulate multiple records through asp.

Original Author: Sumit Dhingra

Inputs

Nothing

Assumptions

The code works against the Pubs database that comes with SQL Server.
Customizations Required :
Change the Connection String. You may even use the descriptive connection string instead of using UDL file.
Can put the queries in a stored procedure and then call the stored procedure from the web page.
Can add Insert/Delete functionality too.

Returns

Nothing

Code

<%@ Language="VBScript" %>
<%
option explicit
Response.Buffer = True

Dim StrConn
Dim objConnection
Dim AuthorsRS, PubsRS
Dim au_id, Saveflg, Items, Title_Id, stor_Id, Ord_Num, Qty
Dim SQL
Dim i, Counter

'Setting up the Connection
StrConn = "File Name=C:TestPubs.udl"
Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.ConnectionString = StrConn
' open the connection
objConnection.Open

' Get the Form Values
SaveFlg = Request.Form("hSaveFlg")
au_id = Request.Form("hau_id")
Items = Request.Form("hItems")

If au_id = "" or ISNULL(au_id) then
au_id = "%"
End If

'---------------------------- Saving the Info to the Database ---------------------------------------
If SaveFlg = "1" Then
Counter = 1
Do While Counter <= (Items - 1)
If Request.Form("Select"&Counter) = "on" Then
Ord_Num = Request.Form("Ord_num"&Counter)
Stor_Id = Request.Form("Stor_Id"&Counter)
Title_Id = Request.Form("Title_Id"&Counter)
Qty = Request.Form("Quantity"&Counter)

' Saving the Info now
SQL = "Update Sales Set Qty = " & qty & " Where stor_id = " & stor_id &_
" and ord_num = '" & ord_num & "' and title_id = '" & title_id & "'"
objConnection.Execute(SQL)

End If
Counter = counter + 1
Loop
End If


' Get the Data for displaying on the Page.
Set AuthorsRS  = objConnection.Execute("Select au_id, au_fname + ' ' + au_lname as Author From Authors")
AuthorsRS.MoveFirst

SQL = "select au_fname, au_lname, s.ord_num, t.title, s.qty, s.stor_id, s.title_id " &_
"from authors a inner join titleauthor ta on a.au_id = ta.au_id inner join sales s " &_
"on ta.title_id = s.title_id inner join titles t on s.title_id = t.title_id " &_
"where a.au_id like '" & au_id & "' order by a.au_fname, au_lname, s.ord_num, s.title_id"

Set PubsRS  = objConnection.Execute(SQL)
PubsRS.MoveFirst
%>


Pubs Grid


















<%
i = 1
Do While Not PubsRS.Eof
Response.Write ""
Response.Write ""
Response.Write ""
Response.Write ""
Response.Write ""
Response.Write ""
i = i + 1
PubsRS.MoveNext
Loop
%>

Author :
<%
Response.Write "

"
%>

  Select All
       Clear All
Select Order # Title Quantity
"
Response.Write ""
Response.Write ""
Response.Write ""
Response.Write "
" & PubsRS("Title") & "






<%
PubsRS.Close
%>

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 68 times

Categories

ASP/ HTML

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.