Previously written in some books:
Page_load event demonstration
Width = "600"
Backcolor = "white"
Bordercolor = "black"
Showfooter = "false"
Cellpadding = 3
Cellspacing = "0"
Font-name = "verdana"
Font-size = "8pt"
Headerstyle-backcolor = "# aaaadd"
Maintainstate = "false"
/>
It seems that since the release of vs2003, two files can be written to truly implement the separation of pages and logic. It seems that I like this programming mode, which is too similar to VB6 and easy to use.
The following are my use of VB. net and C # display a piece of code from SQL server data to the grid, saving the form design part. Of course, there is no modification yet (note that both methods of connecting to the database string are acceptable ):
VB.net
Imports system. Data
Imports system. Data. sqlclient
Public class webform1
Inherits system. Web. UI. Page
# Region "code generated by web forms designer"
Private sub page_load (byval sender as system. Object, byval e as system. eventargs) handles mybase. Load
'User code to place the initialization page here
Dim con as sqlconnection = new sqlconnection ("Server =.; uid = sa; Pwd =; database = test ;")
Con. open ()
Dim ad as sqldataadapter = new sqldataadapter ("select * From g_gzzxzl", con)
Dim ds as dataset = new dataset
Ad. Fill (DS)
Response. Write (Ds. Tables (0). Rows (0) (2). tostring ())
Datagrid1.datasource = DS
Datagrid1.databind ()
End sub
End Class
C #
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;
Using system. Data. sqlclient;
Namespace Test
{
///
/// Summary of webform1.
///
Public class webform1: system. Web. UI. Page
{
Protected system. Web. UI. webcontrols. textbox txtname;
Protected system. Web. UI. webcontrols. Button button1;
Protected system. Web. UI. webcontrols. DataGrid datagrid1;
Protected system. Web. UI. webcontrols. Label label1;
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
// Sqlconnection con = new sqlconnection ("Initial catalog = test; Data Source =.; uid = sa; Pwd =; Connect timeout = 60 ;");
Sqlconnection con = new sqlconnection ("Server =.; uid = sa; Pwd =; database = test ;");
Con. open ();
Sqldataadapter ad = new sqldataadapter ("select * From g_gzzxzl", con );
Dataset DS = new dataset ();
Ad. Fill (DS );
Response. Write (Ds. Tables [0]. Rows [0] [2]. tostring ());
Datagrid1.datasource = Ds;
Datagrid1.databind ();
}
# Code generated by region web Form Designer
}
}