求助,如何按照我规定的顺序来显示数据
大家好,我现在利用DataGrid控件来显示sql 里面的数据。sql里面有一张数据表,这种表中“序号”是主键现在我有一个整型的数组,现在我想按照数据里面的数据在datagrid控件中显示。
假如 数组时a【10】,里面存储的数据分别是,1,3,4,5,7,6,9,8,2,10
我想按照数组里面的序号来在datagrid中显示数据。
<%@ Page Language="VB" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) myDataGrid.DataSource = GetData() myDataGrid.DataBind() End Sub Private Function GetData() As DataTable Dim dt As DataTable = New DataTable For i As Integer = 1 To 5 dt.Columns.Add(New DataColumn("", GetType(System.String))) Next 'For i As Integer = 0 To 4 ' dt.Rows.Add(dt.NewRow) ' For j As Integer = 0 To 4 ' dt.Rows(i)(j) = i.ToString() ' Next 'Next Dim a(9) As String For i As Integer = 0 To 9 '这里模拟一个数组 a(i) = i Next For i As Integer = 0 To 9 '将数组的值填入datagrid dt.Rows.Add(dt.NewRow) For j As Integer = 0 To 4 dt.Rows(i)(j) = i.ToString() Next Next Return dt End Function </script> <html xmlns="http://www. runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> <asp:DataGrid ID="myDataGrid" runat="server"> </asp:DataGrid> </form> </body> </html>