The Visual C# .Net Data Web Form page - Dataweb_booknote.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_booknote.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_booknote.

/// </summary>

public class Dataweb_booknote : System.Web.UI.Page

{

protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;

protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;

protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;

protected System.Data.OleDb.OleDbConnection oleDbConnection1;

protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;

protected Web_VCnet.Dataweb_booknotedset objDataweb_booknotedset;

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

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

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

protected System.Web.UI.WebControls.Button btn_add;

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

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

protected System.Web.UI.WebControls.Button LastPage;

protected System.Web.UI.WebControls.Button NextPage;

protected System.Web.UI.WebControls.Button PreviousPage;

protected System.Web.UI.WebControls.Button FirstPage;

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

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

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

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

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

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

protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;

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

{

// Put user code to initialize the page here

// controls visible ...

sub_showcontrol(true);

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_booknotedset;

// Enable paging.

masterDataGrid.AllowPaging = true;

masterDataGrid.PageSize = 5;

if (!Page.IsPostBack)

{

FirstPage_Click(sender, e);

this.Label_addinfo.Text = "";

this.txtoperation.Text = "";

}

}

else

{

this.objDataweb_booknotedset = ((Web_VCnet.Dataweb_booknotedset)(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_booknotedset objDataSetTemp;

objDataSetTemp = new Web_VCnet.Dataweb_booknotedset();

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_booknotedset.Clear();

// Merge the records into the main dataset.

objDataweb_booknotedset.Merge(objDataSetTemp);

}

catch (System.Exception eLoadMerge)

{

// Add your error handling code here.

throw eLoadMerge;

}

}

public void FillDataSet(Web_VCnet.Dataweb_booknotedset 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();

}

}

//controls visible ...

private void sub_showcontrol( bool bval)

{

this.Label_nav1.Visible = bval;

this.Label_nav2.Visible = bval;

this.FirstPage.Visible = bval;

this.PreviousPage.Visible = bval;

this.NextPage.Visible = bval;

this.LastPage.Visible = bval;

this.lbnavigation.Visible = bval;

this.Label_add1.Visible = bval;

this.Label_add2.Visible = bval;

this.btn_add.Visible = bval;

this.Label_addinfo.Visible = bval;

}

 

//***************************** Navigation ...

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

{

masterDataGrid.CurrentPageIndex = 0;

//Enabled buttons and bind the data

show_Button(masterDataGrid.CurrentPageIndex);

}

//Enabled buttons and bind the data

private void show_Button( int vCurrentPage)

{

int vcpage = vCurrentPage + 1;

int vPagecount;

if (vCurrentPage == 0)

{

FirstPage.Enabled = false;

PreviousPage.Enabled = false;

NextPage.Enabled = true;

LastPage.Enabled = true;

goto pt1;

}

else

{

if (vCurrentPage == (masterDataGrid.PageCount - 1))

{

FirstPage.Enabled = true;

PreviousPage.Enabled = true;

NextPage.Enabled = false;

LastPage.Enabled = false;

goto pt1;

}

else

{

FirstPage.Enabled = true;

PreviousPage.Enabled = true;

NextPage.Enabled = true;

LastPage.Enabled = true;

}

}

pt1:

masterDataGrid.DataBind();

vPagecount = masterDataGrid.PageCount;

this.lbnavigation.Text = "Page : " + System.Convert.ToString(vcpage) + " of " + System.Convert.ToString(vPagecount) + " ............ info: Page size = 5";

}

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

{

masterDataGrid.CurrentPageIndex = Math.Max(0, masterDataGrid.CurrentPageIndex - 1);

//Enabled buttons and bind the data

show_Button(masterDataGrid.CurrentPageIndex);

}

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

{

masterDataGrid.CurrentPageIndex = Math.Min(masterDataGrid.PageCount - 1, masterDataGrid.CurrentPageIndex + 1);

//Enabled buttons and bind the data

show_Button(masterDataGrid.CurrentPageIndex);

}

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

{

masterDataGrid.CurrentPageIndex = masterDataGrid.PageCount - 1;

//Enabled buttons and bind the data

show_Button(masterDataGrid.CurrentPageIndex);

}

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

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

{

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

this.masterDataGrid.DataBind();

this.txtoperation.Text = "Edit operation";

}

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

{

this.masterDataGrid.EditItemIndex = -1;

this.masterDataGrid.DataBind();

this.Label_addinfo.Text = "";

this.txtoperation.Text = "";

}

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

{

string vfirstname;

string vfathername;

string vname;

string vcountry;

string vcity;

if (this.txtoperation.Text == "Edit operation")

{

// 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]));

vname = tb.Text;

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

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

vfirstname = tb.Text;

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

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

vfathername = 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_booknotedset.booknoteRow r;

r = objDataweb_booknotedset.booknote.FindBybookid(int.Parse(key));

// Updates the dataset table.

r.name = vname;

r.first_name = vfirstname;

r.father_name = vfathername;

r.country = vcountry;

r.city = vcity;

// Calls a OLE statement to update the database from the dataset

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

// Takes the DataGrid row out of editing mode

masterDataGrid.EditItemIndex = -1;

// Refreshes the grid

masterDataGrid.DataBind();

return;

}

if (this.txtoperation.Text == "Add operation")

{

// 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]));

vname = tb.Text;

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

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

vfirstname = tb.Text;

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

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

vfathername = 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_booknotedset.booknoteRow r;

r = objDataweb_booknotedset.booknote.AddbooknoteRow(vcity, vcountry, vfathername, vfirstname, vname);

// Updates the dataset table.

// Calls a OLE statement to update the database from the dataset

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

r.Table.AcceptChanges();

//Go to last page of DataGrid, or last row of DataGrid

masterDataGrid.CurrentPageIndex = masterDataGrid.PageCount - 1;

//Eenabled buttons and bind the data

show_Button(masterDataGrid.CurrentPageIndex);

// Takes the DataGrid row out of editing mode

masterDataGrid.EditItemIndex = -1;

// Refreshes the grid

masterDataGrid.DataBind();

this.Label_addinfo.Text = "";

this.txtoperation.Text = "";

return;

}

 

}

 

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

{

//show first page ...

this.FirstPage_Click(sender, e);

this.txtoperation.Text = "Add operation";

//Add new record

DataRow drow = this.objDataweb_booknotedset.Tables["booknote"].NewRow();

drow["name"] = "";

drow["first_name"] = "";

drow["father_name"] = "";

drow["country"] = "";

drow["city"] = "";

this.Label_addinfo.Text = "New row to be add ...";

this.objDataweb_booknotedset.booknote.Rows.InsertAt(drow, 0);

masterDataGrid.EditItemIndex = 0;

masterDataGrid.DataBind();

}

 

}

}

   
  
 



 

      Return