The Visual Basic .Net Data Web Form page - Dataweb_book.aspx, Text Codes
 
 
 

       
      Return



 


     

 The codes  corresponding ...
   
 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 ...
 

 
using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace Web_VCnet

{

/// <summary>

/// Summary description for Dataweb_book.

/// </summary>

public class Dataweb_book : System.Web.UI.Page

{

protected System.Data.OleDb.OleDbConnection oleDbConnection1;

protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;

protected Web_VCnet.Dataweb_bookdset objDataweb_bookdset;

protected System.Web.UI.WebControls.DataGrid masterDataGrid;

protected System.Web.UI.WebControls.HyperLink HyperLink2;

protected System.Web.UI.WebControls.LinkButton LinkButton3;

protected System.Web.UI.WebControls.Label Label1;

protected System.Web.UI.WebControls.Label lbnavigation;

protected System.Web.UI.WebControls.LinkButton LinkButton4;

protected System.Web.UI.WebControls.LinkButton LinkButton5;

protected System.Web.UI.WebControls.LinkButton LinkButton6;

protected System.Web.UI.WebControls.LinkButton LinkButton7;

protected System.Web.UI.WebControls.LinkButton LinkButton8;

protected System.Web.UI.WebControls.LinkButton LinkButton9;

protected System.Web.UI.WebControls.LinkButton LinkButton10;

protected System.Web.UI.WebControls.LinkButton LinkButton2;

protected System.Web.UI.WebControls.Panel Panel1;

protected System.Web.UI.WebControls.LinkButton LinkButton1;

protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;

protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;

protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;

protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;

protected System.Web.UI.WebControls.TextBox TextBox1;

//variable

int vpagecount;

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

if (Session["mydatset"] == null)

{

try

{

this.LoadDataSet();

this.masterDataGrid.SelectedIndex = -1;

this.masterDataGrid.DataBind();

}

catch (System.Exception eLoad)

{

this.Response.Write(eLoad.Message);

}

Session["mydataset"] = this.objDataweb_bookdset;

// Enable paging.

masterDataGrid.AllowPaging = true;

masterDataGrid.PageSize = 5;

if (!Page.IsPostBack)

{

masterDataGrid.DataSource = this.objDataweb_bookdset;

masterDataGrid.DataBind();

//Show the 10 first Page numbers

sub_showpagenumbers();

LinkButton1_Click(sender, e);

}

}

else

{

this.objDataweb_bookdset = ((Web_VCnet.Dataweb_bookdset)(Session["mydatset"]));

}

}


 
      Wwb Form Designer generated code

public void 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.

Web_VCnet.Dataweb_bookdset objDataSetTemp;

objDataSetTemp = new Web_VCnet.Dataweb_bookdset();

try

{

// Attempt to fill the temporary dataset.

this.FillDataSet(objDataSetTemp);

}

catch (System.Exception eFillDataSet)

{

// Add your error handling code here.

throw eFillDataSet;

}

try

{

// Empty the old records from the dataset.

objDataweb_bookdset.Clear();

// Merge the records into the main dataset.

objDataweb_bookdset.Merge(objDataSetTemp);

}

catch (System.Exception eLoadMerge)

{

// Add your error handling code here.

throw eLoadMerge;

}

}

public void FillDataSet(Web_VCnet.Dataweb_bookdset dataSet)

{

// 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.

this.oleDbConnection1.Open();

// Attempt to fill the dataset through the OleDbDataAdapter1.

this.oleDbDataAdapter1.Fill(dataSet);

}

catch (System.Exception fillException)

{

// 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.

this.oleDbConnection1.Close();

}

}

//Show the 10 first Page numbers

public void sub_showpagenumbers()

{

int i;

vpagecount = this.masterDataGrid.PageCount;

if (vpagecount <= 10)

{

for (i = 0 ; i <= 10; i++)

{

switch(i)

{

case 1:

if ((i <= vpagecount) && (i == 1))

{

this.LinkButton1.Visible = true;

}

else

{

this.LinkButton1.Visible = false;

}

break;

case 2:

if ((i <= vpagecount) && (i == 2))

{

this.LinkButton2.Visible = true;

}

else

{

this.LinkButton2.Visible = false;

}

break;

case 3:

if ((i <= vpagecount) && (i == 3))

{

this.LinkButton3.Visible = true;

}

else

{

this.LinkButton3.Visible = false;

}

break;

case 4:

if ((i <= vpagecount) && (i == 4))

{

this.LinkButton4.Visible = true;

}

else

{

this.LinkButton4.Visible = false;

}

break;

case 5:

if ((i <= vpagecount) && (i == 5))

{

this.LinkButton5.Visible = true;

}

else

{

this.LinkButton5.Visible = false;

}

break;

case 6:

if ((i <= vpagecount) && (i == 6))

{

this.LinkButton6.Visible = true;

}

else

{

this.LinkButton6.Visible = false;

}

break;

case 7:

if ((i <= vpagecount) && (i == 7))

{

this.LinkButton7.Visible = true;

}

else

{

this.LinkButton7.Visible = false;

}

break;

case 8:

if ((i <= vpagecount) && (i == 8))

{

this.LinkButton8.Visible = true;

}

else

{

this.LinkButton8.Visible = false;

}

break;

case 9:

if ((i <= vpagecount) && (i == 9))

{

this.LinkButton9.Visible = true;

}

else

{

this.LinkButton9.Visible = false;

}

break;

case 10:

if ((i <= vpagecount) && (i == 10))

{

this.LinkButton10.Visible = true;

}

else

{

this.LinkButton10.Visible = false;

}

break;

}

}

}

}

// ***************************** Edit, Update, Cancel

private void masterDataGrid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

this.masterDataGrid.EditItemIndex = e.Item.ItemIndex;

this.masterDataGrid.DataBind();

}

private void masterDataGrid_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

this.masterDataGrid.EditItemIndex = -1;

this.masterDataGrid.DataBind();

}

private void masterDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

string vfirstname;

string vfathername;

string vname;

string vcountry;

string vcity;

// Gets the value of the key field of the row being updated

string key = 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.

System.Web.UI.WebControls.TextBox tb;

// Gets the value the TextBox control in the 2nd column

// tb = ((System.Web.UI.WebControls.TextBox)(e.Item.Cells[1].Controls[0]));

//tb = ((TextBox)(e.Item.Cells[1].Controls[0]));

tb = ((TextBox)(e.Item.Cells[1].Controls[0]));

vfirstname = tb.Text;

this.TextBox1.Text=tb.Text;

// Gets the value the TextBox control in the 3th column

tb = ((System.Web.UI.WebControls.TextBox)(e.Item.Cells[2].Controls[0]));

vfathername = tb.Text;

// Gets the value the TextBox control in the 4th column

tb = ((System.Web.UI.WebControls.TextBox)(e.Item.Cells[3].Controls[0]));

vname = tb.Text;

// Gets the value the TextBox control in the 5th column

tb = ((System.Web.UI.WebControls.TextBox)(e.Item.Cells[4].Controls[0]));

vcountry = tb.Text;

// Gets the value the TextBox control in the 6th column

tb = ((System.Web.UI.WebControls.TextBox)(e.Item.Cells[5].Controls[0]));

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.

Dataweb_bookdset.booknoteRow r;

r = objDataweb_bookdset.booknote.FindBybookid(int.Parse(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

this.oleDbDataAdapter1.Update(objDataweb_bookdset, "booknote");

this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;

// Takes the DataGrid row out of editing mode

masterDataGrid.EditItemIndex = -1;

// Refreshes the grid

masterDataGrid.DataBind();

}

// ******************** Navigation, page numbers

private void LinkButton1_Click(object sender, System.EventArgs e)

{

masterDataGrid.CurrentPageIndex = System.Convert.ToInt16(LinkButton1.Text) - 1;

//Page numbers navigation, load page

sub_oppagenumbers(LinkButton1.Text);

LinkButton1.Enabled = false;

}

//Page numbers navigation, load page

private void sub_oppagenumbers( string vcpage)

{

vpagecount = this.masterDataGrid.PageCount;

this.lbnavigation.Text = " Page Numbers operation - page size = 5 records ......... Page : " + System.Convert.ToString(vcpage) + " of " + System.Convert.ToString(vpagecount);

if ( LinkButton1.Visible == true)

LinkButton1.Enabled = true;

if ( LinkButton2.Visible == true)

LinkButton2.Enabled = true;

if ( LinkButton3.Visible == true)

LinkButton3.Enabled = true;

if ( LinkButton4.Visible == true)

LinkButton4.Enabled = true;

if ( LinkButton5.Visible == true)

LinkButton5.Enabled = true;

if ( LinkButton6.Visible == true)

LinkButton6.Enabled = true;

if ( LinkButton7.Visible == true)

LinkButton7.Enabled = true;

if ( LinkButton8.Visible == true)

LinkButton8.Enabled = true;

if ( LinkButton9.Visible == true)

LinkButton9.Enabled = true;

if ( LinkButton10.Visible == true)

LinkButton10.Enabled = true;

// Takes the DataGrid row out of editing mode

masterDataGrid.EditItemIndex = -1;

masterDataGrid.DataSource = this.objDataweb_bookdset;

masterDataGrid.DataBind();

}

 

private void LinkButton2_Click(object sender, System.EventArgs e)

{

masterDataGrid.CurrentPageIndex = System.Convert.ToInt16(LinkButton2.Text) - 1;

//Page numbers navigation, load page

sub_oppagenumbers(LinkButton2.Text);

LinkButton2.Enabled = false;

}

private void LinkButton3_Click(object sender, System.EventArgs e)

{

masterDataGrid.CurrentPageIndex = System.Convert.ToInt16(LinkButton3.Text) - 1;

//Page numbers navigation, load page

sub_oppagenumbers(LinkButton3.Text);

LinkButton3.Enabled = false;

}

private void LinkButton4_Click(object sender, System.EventArgs e)

{

masterDataGrid.CurrentPageIndex = System.Convert.ToInt16(LinkButton4.Text) - 1;

//Page numbers navigation, load page

sub_oppagenumbers(LinkButton4.Text);

LinkButton4.Enabled = false;

}

private void LinkButton5_Click(object sender, System.EventArgs e)

{

masterDataGrid.CurrentPageIndex = System.Convert.ToInt16(LinkButton5.Text) - 1;

//Page numbers navigation, load page

sub_oppagenumbers(LinkButton5.Text);

LinkButton5.Enabled = false;

}

private void LinkButton6_Click(object sender, System.EventArgs e)

{

masterDataGrid.CurrentPageIndex = System.Convert.ToInt16(LinkButton6.Text) - 1;

//Page numbers navigation, load page

sub_oppagenumbers(LinkButton6.Text);

LinkButton6.Enabled = false;

}

private void LinkButton7_Click(object sender, System.EventArgs e)

{

masterDataGrid.CurrentPageIndex = System.Convert.ToInt16(LinkButton7.Text) - 1;

//Page numbers navigation, load page

sub_oppagenumbers(LinkButton7.Text);

LinkButton7.Enabled = false;

}

private void LinkButton8_Click(object sender, System.EventArgs e)

{

masterDataGrid.CurrentPageIndex = System.Convert.ToInt16(LinkButton8.Text) - 1;

//Page numbers navigation, load page

sub_oppagenumbers(LinkButton8.Text);

LinkButton8.Enabled = false;

}

private void LinkButton9_Click(object sender, System.EventArgs e)

{

masterDataGrid.CurrentPageIndex = System.Convert.ToInt16(LinkButton9.Text) - 1;

//Page numbers navigation, load page

sub_oppagenumbers(LinkButton9.Text);

LinkButton9.Enabled = false;

}

private void LinkButton10_Click(object sender, System.EventArgs e)

{

masterDataGrid.CurrentPageIndex = System.Convert.ToInt16(LinkButton10.Text) - 1;

//Page numbers navigation, load page

sub_oppagenumbers(LinkButton10.Text);

LinkButton10.Enabled = false;

}



 

 

}

}

   
  
 



 

      Return