How to use the DataGrid control

Source: Internet
Author: User
Tags datagrid example
Datagrid|datagrid controls [Visual Basic, C #, JScript] The following example shows how to use the DataGrid control to display items from a data source.
[Visual Basic]
<%@ Page language= "VB" autoeventwireup= "True"%>
<%@ Import namespace= "System.Data"%>

<script language= "VB" runat= "Server" >
Function CreateDataSource () as ICollection
Dim DT as New DataTable ()
Dim Dr as DataRow

Dt. Columns.Add (New DataColumn ("IntegerValue", GetType (Int32))
Dt. Columns.Add (New DataColumn ("StringValue", GetType (String))
Dt. Columns.Add (New DataColumn ("Currencyvalue", GetType (Double))

Dim I as Integer
For i = 0 to 8
Dr = dt. NewRow ()

Dr (0) = i
DR (1) = "Item" + i.tostring ()
DR (2) = 1.23 * (i + 1)

Dt. Rows.Add (DR)
Next I

Dim DV as New DataView (DT)
Return DV
End Function ' CreateDataSource


Sub Page_Load (sender as Object, E as EventArgs)

If not IsPostBack Then
' Load This data is only once.
Itemsgrid.datasource = CreateDataSource ()
Itemsgrid.databind ()
End If
End Sub ' Page_Load

</script>

<body>

<form runat=server>


<b>product list</b>

<asp:datagrid id= "Itemsgrid"
Bordercolor= "BLACK"
Borderwidth= "1"
Cellpadding= "3"
Autogeneratecolumns= "true"
runat= "Server" >

</HeaderStyle>

</asp:DataGrid>

</form>

</body>




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.