Asp. Net:datalist control's Column output function

Source: Internet
Author: User
Tags eval
The Asp.net| control DataList control displays data items in a repeating list, and can also support selecting and editing items. You can use a template to define the contents and layout of a list item in DataList, and its biggest feature is that you can display data in columns. In the following sections, we will explain in detail.

A detailed explanation of the 9.3 DataList control

9.3.1 DataList control's output function

The DataList control is designed to be used to disaggregate the output data, the data to be exported is in its <ItemTemplate> properties, each <Blockquote> is a forced wrap, and each row can have more than one field of data. When binding data, use the <%#%> syntax.

Let's look at a breakdown output instance of a DataList control:
Create a new Web Form in the Datacon Web project, named Datalist_sample1.aspx, and add a DataList control. The database uses Studentinfor.mdb.
The DataList control properties are set as follows:
<asp:datalist id= "DataList1"
runat= "Server" bordercolor= "#3366CC"
Borderstyle= "None" backcolor= "white"
cellpadding= "0" gridlines= "Both"
Borderwidth= "1px" repeatcolumns= "2"
Font-size= "X-small" height= "321px"
Width= "432px" repeatdirection= "Horizontal" >
<separatorstyle backcolor= "#99CCCC" ></SeparatorStyle>
<itemstyle font-size= "X-small"
Forecolor= "BLACK" backcolor= "white" ></ItemStyle>
<ItemTemplate>
<font face= "Song Body" >
<blockquote>
Name: <%# DataBinder.Eval (Container.DataItem, "name")%>
</blockquote>
<blockquote>
<br> No.: <%# DataBinder.Eval (Container.DataItem, "id")%>
<br> Sex: <%# DataBinder.Eval (Container.DataItem, "sex")%>
<br> Specialty: <%# DataBinder.Eval (Container.DataItem, "major")%>
<br> class: <%# DataBinder.Eval (Container.DataItem, "class")%>
</blockquote></FONT>
</ItemTemplate>
</asp:DataList>
In the properties of the DataList control, what we need to know is the RepeatColumns property, whose value indicates that the data is output in several columns.

The following is the logical code section for datalist_sample1.aspx:
'-----Code begin------
'--omitting a reference to a namespace
Public Class Datalist_sample1
Inherits System.Web.UI.Page
#Region the code generated by the Web Forms Designer
' Omit the code generated by the form designer here
<system.diagnostics.debuggerstepthrough () > Private Sub InitializeComponent ()
End Sub
Protected WithEvents DataList1 as System.Web.UI.WebControls.DataList
' NOTE: The following placeholder declarations are required by the Web Forms Designer.
' Do not delete or move it.
Private Designerplaceholderdeclaration as System.Object
Private Sub Page_Init (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Mybase.init
' CodeGen: This method call is required by the Web Forms Designer
' Do not modify it using the Code Editor.
InitializeComponent ()
End Sub
#End Region
Private Sub Page_Load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles MyBase.Load
' The user code to place the initialization page here
GetData ()
End Sub
' Read data
Sub GetData ()
Dim Mycon as Oledb.oledbconnection
Try
Mycon = New oledb.oledbconnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Server.MapPath (".") + "\ Studentinfor.mdb ")
Dim mycmd as Oledb.oledbdataadapter = New oledb.oledbdataadapter ("SELECT * from Student", mycon)
Dim dt as Data.dataset = New Data.dataset
myCMD. Fill (DT)
Datalist1.datasource = dt. Tables (0). DefaultView
Datalist1.databind ()
Catch ex as Exception
Response.Write ("program error, information described below:<br>" & Ex.) message.tostring)
Finally
Mycon. Close ()
End Try
End Sub
End Class
'-----Code End--------
After you save the compilation, the results of the run are shown in Figure 9.14.


Figure 9.14 Datalist_sample1.aspx Run Results



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.