Introduction to asp+ Grammar (vi)----Database Chapter

Source: Internet
Author: User
Tags button type end sql
asp+| Data | database | grammar/*
Article Source: http://www.aspCool.com reprint Please specify, thank you!
* * list, data and data bar set
Asp+ provides us with a set of data tables and lists of data controls. These controls can help us customize our UI (user interFace) without considering a database or other database. For example, in the following example, we will describe how the <asp:datagrid runat=server> control provides data to us through SQL statements.
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.SQL"%>

<link rel= "stylesheet" href= "Intro.css" >

<script language= "VB" runat=server>

Sub SubmitBtn_Click (Sender as Object, E as EventArgs)

Dim DS as DataSet
Dim MyConnection as SqlConnection
Dim MyCommand as Sqldatasetcommand
' The following is a database connection
MyConnection = New SqlConnection ("server=localhost;uid=sa;pwd=;d atabase=pubs")
mycommand = New Sqldatasetcommand ("select * from Titles where type= '" + Category.SelectedItem.Value + "", MyConnection)

DS = new DataSet ()
Mycommand.filldataset (DS, "Titles")

Mylist.datasource = DS. Tables ("Titles"). DefaultView
Mylist.databind ()

End Sub


</script>

<body>

<center>

<form action= "intro75.aspx" method= "POST" runat= "Server" >

<asp:adrotator advertisementfile= "Ads.xml" bordercolor= "Black" borderwidth=1 runat= "Server"/>


Category: <asp:dropdownlist id= "Category" runat=server>
<asp:listitem >psychology</asp:listitem>
<asp:listitem >business</asp:listitem>
<asp:listitem >popular_comp</asp:listitem>
</asp:dropdownlist>

<asp:button type=submit text= "Lookup" onclick= "SubmitBtn_Click" runat= "Server"/>

<p>

<asp:datagrid id= "MyList" headerstyle-backcolor= "#aaaadd" backcolor= "#ccccff" runat= "Server"/>

</form>

</center>

</body>

The running example of this example
Http://tutorial.superexpert.com/quickstart/aspplus/samples/webforms/intro/intro75.aspx

Data Grid Control <asp:datagrid runat=server>
Provides a very simple way to display the results of a data query with a traditional UI section. Asp+ developers can now also pass <asp:datalist runat=server>
To customize the data list display to customize the information

<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.SQL"%>

<link rel= "stylesheet" href= "Intro.css" >

<script language= "VB" runat=server>

Sub SubmitBtn_Click (Sender as Object, E as EventArgs)

Dim DS as DataSet
Dim MyConnection as SqlConnection
Dim MyCommand as Sqldatasetcommand

MyConnection = New SqlConnection ("server=localhost;uid=sa;pwd=;d atabase=pubs")
mycommand = New Sqldatasetcommand ("select * from Titles where type= '" + Category.SelectedItem.Value + "", MyConnection)

DS = new DataSet ()
Mycommand.filldataset (DS, "Titles")

Mylist.datasource = DS. Tables ("Titles"). DefaultView
Mylist.databind ()

End Sub

</script>

<body>

<center>

<form action= "intro8.aspx" method= "POST" runat= "Server" >

<asp:adrotator advertisementfile= "Ads.xml" bordercolor= "bla

[1] [2] Next page



Related Article

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.