Learning ASP. NET (1)

Source: Internet
Author: User

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

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.