|
|
1-
Web.Config file, modify ...
The
Data
Web Form to work probably with connection, add the folowing string in
color marroon
<?xml
version="1.0"
encoding="utf-8"
?> < configuration>
<system.web>
<!--
DYNAMIC DEBUG COMPILATION
Set compilation debug="true" to insert debugging symbols (.pdb
information)
into the compiled page. Because this creates a larger file that executes
more slowly, you should set this value to true only when debugging and to
false at all other times. For more information, refer to the
documentation about
debugging ASP.NET files.
-- >
<compilation
defaultLanguage="vb"
debug="true"
/>
<!--
CUSTOM ERROR MESSAGES
Set customErrors mode="On" or "RemoteOnly" to enable custom error
messages, "Off" to disable.
Add <error> tags for each of the errors you want to handle.
"On" Always display custom (friendly) messages.
"Off" Always display detailed ASP.NET error information.
"RemoteOnly" Display custom (friendly) messages only to users not running
on the local Web server. This setting is recommended for security
purposes, so
that you do not display application detail information to remote clients.
-- >
<customErrors
mode="RemoteOnly"
/>
<!--
AUTHENTICATION
This section sets the authentication policies of the application.
Possible modes are "Windows",
"Forms", "Passport" and "None"
"None" No authentication is performed.
"Windows" IIS performs authentication (Basic, Digest, or Integrated
Windows) according to
its settings for the application. Anonymous access must be disabled in
IIS.
"Forms" You provide a custom form (Web page) for users to enter their
credentials, and then
you authenticate them in your application. A user credential token is
stored in a cookie.
"Passport" Authentication is performed via a centralized authentication
service provided
by Microsoft that offers a single logon and core profile services for
member sites.
-- >
<authentication
mode="Windows"
/>
<!--
AUTHORIZATION
This section sets the authorization policies of the application. You can
allow or deny access
to application resources by user or role. Wildcards: "*" mean everyone,
"?" means anonymous
(unauthenticated) users.
-- >
<authorization>
<allow
users="*"
/>
<!--
Allow all users -->
<!--
<allow users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
<deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-- >
</authorization>
<!--
APPLICATION-LEVEL TRACE LOGGING
Application-level tracing enables trace log output for every page within
an application.
Set trace enabled="true" to enable application trace logging. If
pageOutput="true", the
trace information will be displayed at the bottom of each page.
Otherwise, you can view the
application trace log by browsing the "trace.axd" page from your web
application
root.
-- >
<trace
enabled="false"
requestLimit="10"
pageOutput="false"
traceMode="SortByTime"
localOnly="true"
/>
<!--
SESSION STATE SETTINGS
By default ASP.NET uses cookies to identify which requests belong to a
particular session.
If cookies are not available, a session can be tracked by adding a
session identifier to the URL.
To disable cookies, set sessionState cookieless="true".
-- >
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data
source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
<identity impersonate="true"/>
<!--
GLOBALIZATION
This section sets the globalization settings of the application.
-- >
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
/>
</system.web>
</ configuration>
|
2. The Web Form page - Dataweb_book.aspx , modify
...
The text
Code
is red color, the codes added manuel ... |
|
Public
Class
Dataweb_book
Inherits
System.Web.UI.Page
Public vpagecount As Integer
Wwb Form
Designer generated code |
Private Sub
Page_Load(ByVal
sender As System.Object, ByVal
e As System.EventArgs) Handles
MyBase.Load
'Put
user code to initialize the page here
If
Session("mydatset") Is Nothing Then
Try
Me.LoadDataSet()
Me.masterDataGrid.SelectedIndex
= -1
Catch eLoad As
System.Exception
Me.Response.Write(eLoad.Message)
End Try
Session("mydataset") = Me .objDataweb_bookdset
' If
Not Page.IsPostBack Then
With
masterDataGrid
' Enable paging.
.AllowPaging =
True
.PageSize
= 5
End
With
If Not Page.IsPostBack Then
masterDataGrid.DataSource = Me .objDataweb_bookdset
masterDataGrid.DataBind()
'Show the 10 first Page numbers
sub_showpagenumbers()
LinkButton1_Click(sender, e)
End
If
Else
Me.objDataweb_bookdset = CType(Session("mydatset"),
Dataweb_bookdset)
End
If
End
Sub
Public
Sub
LoadDataSet()
'Create a new dataset to hold the records returned from
the call to FillDataSet.
'A
temporary dataset is used because filling the existing
dataset would
'require the databindings to be rebound.
Dim
objDataSetTemp As
Web_VBnet.Dataweb_bookdset
objDataSetTemp =
New
Web_VBnet.Dataweb_bookdset
Try
'Attempt to fill the temporary dataset.
Me.FillDataSet(objDataSetTemp)
Catch
eFillDataSet As
System.Exception
'Add
your error handling code here.
Throw
eFillDataSet
End
Try
Try
'Empty the old records from the dataset.
objDataweb_bookdset.Clear()
'Merge the records into the main dataset.
objDataweb_bookdset.Merge(objDataSetTemp)
Catch
eLoadMerge As
System.Exception
'Add
your error handling code here.
Throw
eLoadMerge
End
Try
End
Sub
Public
Sub
FillDataSet(ByVal
dataSet As
Web_VBnet.Dataweb_bookdset)
'Turn off constraint checking before the dataset is
filled.
'This allows the adapters to fill the dataset without
concern
'for
dependencies between the tables.
dataSet.EnforceConstraints =
False
Try
'Open the connection.
Me.OleDbConnection1.Open()
'Attempt to fill the dataset through the
OleDbDataAdapter1.
Me.OleDbDataAdapter1.Fill(dataSet)
Catch
fillException As
System.Exception
'Add
your error handling code here.
Throw
fillException
Finally
'Turn constraint checking back on.
dataSet.EnforceConstraints =
True
'Close the connection whether or not the exception was
thrown.
Me.OleDbConnection1.Close()
End
Try
End
Sub
'Show the 10 first Page numbers
Public Sub
sub_showpagenumbers()
Dim i As Integer
vpagecount = Me .masterDataGrid.PageCount
If
vpagecount <= 10 Then
For
i = 1 To
10
Select Case
i
Case
1
If i
<= vpagecount And i = 1 Then
Me.LinkButton1.Visible = True
Else
Me.LinkButton1.Visible = False
End
If
Case
2
If i
<= vpagecount And i = 2 Then
Me.LinkButton2.Visible = True
Else
Me.LinkButton2.Visible = False
End
If
Case
3
If i
<= vpagecount And i = 3 Then
Me.LinkButton3.Visible = True
Else
Me.LinkButton3.Visible = False
End
If
Case
4
If i
<= vpagecount And i = 4 Then
Me.LinkButton4.Visible = True
Else
Me.LinkButton4.Visible = False
End
If
Case
5
If i
<= vpagecount And i = 5 Then
Me.LinkButton5.Visible = True
Else
Me.LinkButton5.Visible = False
End
If
Case
6
If i
<= vpagecount And i = 6 Then
Me.LinkButton6.Visible = True
Else
Me.LinkButton6.Visible = False
End
If
Case
7
If i
<= vpagecount And i = 7 Then
Me.LinkButton7.Visible = True
Else
Me.LinkButton7.Visible = False
End
If
Case
8
If i
<= vpagecount And i = 8 Then
Me.LinkButton8.Visible = True
Else
Me.LinkButton8.Visible = False
End
If
Case
9
If i
<= vpagecount And i = 9 Then
Me.LinkButton9.Visible = True
Else
Me.LinkButton9.Visible = False
End
If
Case
10
If i
<= vpagecount And i = 10 Then
Me.LinkButton10.Visible = True
Else
Me.LinkButton10.Visible = False
End
If
End
Select
Next
End
If
End
Sub
'
***************************** Edit, Update, Cancel
Private Sub masterDataGrid_EditCommand(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles
masterDataGrid.EditCommand
Me.masterDataGrid.EditItemIndex
= e.Item.ItemIndex
Me.masterDataGrid.DataBind()
End
Sub
Private Sub masterDataGrid_CancelCommand(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles
masterDataGrid.CancelCommand
Me.masterDataGrid.EditItemIndex
= -1
Me.masterDataGrid.DataBind()
End
Sub
Private Sub masterDataGrid_UpdateCommand(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles
masterDataGrid.UpdateCommand
Dim
vfirstname, vfathername As String
Dim
vname As String
Dim
vcountry, vcity As String
'
Gets the value of the key field of the row being updated
Dim
key As String = Me.masterDataGrid.DataKeys(e.Item.ItemIndex).ToString()
'
Gets get the value of the controls (textboxes) that the
user
'
updated. The DataGrid columns are exposed as the Cells
collection.
'
Each cell has a collection of controls. In this case,
there is only one
'
control in each cell -- a TextBox control. To get its
value,
'
you copy the TextBox to a local instance (which requires
casting)
'
and extract its Text property.
'
'
The first column -- Cells(0) -- contains the Update and
Cancel buttons.
Dim
tb As
TextBox
' Gets the value the TextBox
control in the 2nd column
tb = CType (e.Item.Cells(1).Controls(0),
TextBox)
vfirstname = tb.Text
' Gets the value the TextBox
control in the 3th column
tb = CType (e.Item.Cells(2).Controls(0),
TextBox)
vfathername = tb.Text
' Gets the value the TextBox
control in the 4th column
tb = CType (e.Item.Cells(3).Controls(0),
TextBox)
vname = tb.Text
' Gets the value the TextBox
control in the 6th column
tb = CType (e.Item.Cells(4).Controls(0),
TextBox)
vcountry = tb.Text
' Gets the value the TextBox
control in the 6th column
tb = CType (e.Item.Cells(5).Controls(0),
TextBox)
vcity = tb.Text
'
Finds the row in the dataset table that matches the
'
one the user updated in the grid. This example uses a
'
special Find method defined for the typed dataset, which
'
returns a reference to the row.
Dim
r As
Dataweb_bookdset.booknoteRow
r
=
Me.objDataweb_bookdset.booknote.FindBybookid(key)
'
Updates the dataset table.
r.first_name = vfirstname
r.father_name = vfathername
r.name = vname
r.country = vcountry
r.city = vcity
'
Calls a OLE statement to update the database from the
dataset
Me.OleDbDataAdapter1.Update(Me.objDataweb_bookdset)
Me.objDataweb_bookdset.AcceptChanges()
'
Takes the DataGrid row out of editing mode
Me.masterDataGrid.EditItemIndex
= -1
'
Refreshes the grid
Me.masterDataGrid.DataBind()
End
Sub
'
******************** Navigation, page numbers
Private Sub LinkButton1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
LinkButton1.Click
masterDataGrid.CurrentPageIndex = Int(LinkButton1.Text) -
1
'Page numbers navigation, load page
sub_oppagenumbers(LinkButton1.Text)
LinkButton1.Enabled =
False
End
Sub
'Page numbers navigation, load page
Public Sub sub_oppagenumbers(ByVal vcpage As String)
vpagecount =
Me.masterDataGrid.PageCount
Me.lbnavigation.Text
= " Page Numbers operation - page size = 5 records
......... Page : " + vcpage.ToString + " of " +
vpagecount.ToString
If
LinkButton1.Visible = True Then LinkButton1.Enabled = True
If
LinkButton2.Visible = True Then LinkButton2.Enabled = True
If
LinkButton3.Visible = True Then LinkButton3.Enabled = True
If
LinkButton4.Visible = True Then LinkButton4.Enabled = True
If
LinkButton5.Visible = True Then LinkButton5.Enabled = True
If
LinkButton6.Visible = True Then LinkButton6.Enabled = True
If
LinkButton7.Visible = True Then LinkButton7.Enabled = True
If
LinkButton8.Visible = True Then LinkButton8.Enabled = True
If
LinkButton9.Visible = True Then LinkButton9.Enabled = True
If
LinkButton10.Visible = True Then LinkButton10.Enabled =
True
'
Takes the DataGrid row out of editing mode
Me.masterDataGrid.EditItemIndex
= -1
masterDataGrid.DataSource =
Me.objDataweb_bookdset
masterDataGrid.DataBind()
End
Sub
Private Sub LinkButton2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
LinkButton2.Click
masterDataGrid.CurrentPageIndex = Int(LinkButton2.Text) -
1
'Page numbers navigation, load page
sub_oppagenumbers(LinkButton2.Text)
LinkButton2.Enabled =
False
End
Sub
Private Sub LinkButton3_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
LinkButton3.Click
masterDataGrid.CurrentPageIndex = Int(LinkButton3.Text) -
1
'Page numbers navigation, load page
sub_oppagenumbers(LinkButton3.Text)
LinkButton3.Enabled =
False
End
Sub
Private Sub LinkButton4_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
LinkButton4.Click
masterDataGrid.CurrentPageIndex = Int(LinkButton4.Text) -
1
'Page numbers navigation, load page
sub_oppagenumbers(LinkButton4.Text)
LinkButton4.Enabled =
False
End
Sub
Private Sub LinkButton5_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles
LinkButton5.Click
masterDataGrid.CurrentPageIndex = Int(LinkButton5.Text) -
1
'Page numbers navigation, load page
sub_oppagenumbers(LinkButton5.Text)
LinkButton5.Enabled =
False
End
Sub
Private Sub LinkButton6_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles
LinkButton6.Click
masterDataGrid.CurrentPageIndex = Int(LinkButton6.Text) -
1
'Page numbers navigation, load page
sub_oppagenumbers(LinkButton6.Text)
LinkButton6.Enabled =
False
End
Sub
Private Sub LinkButton7_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles
LinkButton7.Click
masterDataGrid.CurrentPageIndex = Int(LinkButton7.Text) -
1
'Page numbers navigation, load page
sub_oppagenumbers(LinkButton7.Text)
LinkButton7.Enabled =
False
End
Sub
Private Sub LinkButton8_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles
LinkButton8.Click
masterDataGrid.CurrentPageIndex = Int(LinkButton8.Text) -
1
'Page numbers navigation, load page
sub_oppagenumbers(LinkButton8.Text)
LinkButton8.Enabled =
False
End
Sub
Private Sub LinkButton9_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles
LinkButton9.Click
masterDataGrid.CurrentPageIndex = Int(LinkButton9.Text) -
1
'Page numbers navigation, load page
sub_oppagenumbers(LinkButton9.Text)
LinkButton9.Enabled =
False
End
Sub
Private Sub LinkButton10_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles
LinkButton10.Click
masterDataGrid.CurrentPageIndex = Int(LinkButton10.Text) -
1
'Page numbers navigation, load page
sub_oppagenumbers(LinkButton10.Text)
LinkButton10.Enabled =
False
End
Sub
End Class | |
|
| |
|
|