这有效:
Dim cmdSelect As Data.SqlClient.SqlCommand
Dim dtr As Data.SqlClient.SqlDataReader
Dim strSelect As String
strSelect = "SELECT DISTINCT DVIRDate FROM dbo.tblDVIR " _
& "WHERE (DVIRDate > DATEADD(day, - 30, { fn NOW() }))"
cmdSelect = New Data.SqlClient.SqlCommand(strSelect, ConDB)
ConDB.Open()
dtr = cmdSelect.ExecuteReader()
'Bind to Repeater
Repeater1.DataSource = dtr
Repeater1.DataBind()
dtr.Close()
ConDB.Close()
<asp:Repeater ID="Repeater1" runat="server" >
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "DvirDate")%>
<br />
</ItemTemplate>
</asp:Repeater>
但这不会:
Dim db As New DataContext
Dim sel = From a In db.tblDVIRs _
Where a.DVIRDate > DateAdd(DateInterval.Day, -30, Now()) _
Select a.DVIRDate _
Distinct
Repeater1.DataSource = sel
Repeater1.DataBind()
我收到一个 HttpException,“DataBinding:'System.DateTime' 不包含名为 'DvirDate' 的属性。”
有趣的是,当我绑定到具有自动生成的列 = true 的网格视图时,它可以工作并且该列被命名为“项目”
我只是没有在 the 中使用正确的表达databinder.eval
或做其他错误的事情吗?这在 Linq 中应该很容易,我已经尝试了我能想到的一切databinder.eval()
,我一定错过了一些东西。