好的,既然我们在谈论数据表?
那么使用中继器确实不是正确类型的“重复”控件。
因此,每个数据行的重复器对于这种类型的重复来说是好的:
或者这样说:
换句话说,它不适用于像布局这样的表格。
对于像布局这样的表格,我建议使用 gridview - 为此目的更好。
所以,我们可以放入一个网格视图——我使用向导来创建它——然后从页面中删除数据源。无论如何,我们现在有了这个:
<div style="width:20%;margin-left:20px;margin-top:20px">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="table table-hover">
<Columns>
<asp:BoundField DataField="MyMonth" HeaderText="MyMonth" />
<asp:BoundField DataField="Sales" HeaderText="Sales" DataFormatString="{0:C}"/>
</Columns>
</asp:GridView>
</div>
所以,现在我们需要对非常糟糕的数据进行反规范化。该数据看起来像电子表格 - 对于“数据”或“数据驱动的方法”来说并不是很好。
所以,让我们在后面编写这段代码来加载数据。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
LoadGrid
End If
End Sub
Sub LoadGrid()
Dim strSQL As String
strSQL = "SELECT 1 as NMonth, 'January' as MyMonth, January As Sales from tblMonth " &
"UNION SELECT 2 as NMonth, 'Feburary' as MyMonth, Feburary As Sales from tblmonth " &
"UNION SELECT 3 as Nmonth, 'March' as MyMonth, March As Sales from tblmonth " &
"UNION SELECT 4 as Nmonth, 'April' as MyMonth, April As Sales from tblmonth " &
"ORDER BY Nmonth"
Using cmdSQL As New SqlCommand(strSQL, New SqlConnection(My.Settings.TEST4))
cmdSQL.Connection.Open()
Dim rstData As New DataTable
rstData.Load(cmdSQL.ExecuteReader)
GridView1.DataSource = rstData
GridView1.DataBind()
End Using
End Sub
现在我们的输出如下所示:
我们的数据表如下所示:
因此,该数据库需要一些爱和关怀 - 它不应该以这种方式设置(每列以一个月为单位。数据库应该是:
DMonth - (the month - probably better as a date
Sales - (the sales for the month - say money data type)