DataBinding列表视图

时间:2012-04-14 07:58:47

标签: asp.net vb.net

Dim  _tableBackLogs As System.Data.DataTable  



 Do While i - 2 > 0
        _tableBackLogs = Global.DataAccess.GetDataTable("SELECT SubjectID,SubjectName,Grade FROM SubjectPI WHERE RegNo='" & CInt(HttpContext.Current.Session("userName")) & "' AND Status='Fail' AND Semester='" & i - 2 & "'")
        i = i - 2
    Loop

lvBackSubjects.DataSource = _tableBackLogs
lvBackSubjects.DataBind()

这样做只会绑定提供给i的最后一个ListView值的数据。我想要所有的数据。假设i=5。所以我希望ListView拥有i=3,1的数据。希望我不要让你们困惑。

1 个答案:

答案 0 :(得分:0)

看起来循环正在覆盖变量_tableBackLogs。做这样的事情可能会更好:

dim semesters as New System.Text.StringBuilder()

Do While i - 2 > 0
    semesters.Append("'" & i & "',")
    i = i - 2
Loop

' remove the last ,
semesters.Remove(semesters.Length -1,1)

_tableBackLogs = Global.DataAccess.GetDataTable("SELECT SubjectID,SubjectName,Grade FROM SubjectPI WHERE RegNo='" & CInt(HttpContext.Current.Session("userName")) & "' AND Status='Fail' AND Semester in (" & semesters.ToString() & ")"