我正在嘗試創建一個會話,在其中存盤某個列的值。所以我創建了這個串列來顯示選中的值,但是我在另一個頁面 System.Collections.Generic.List`1[System. String] 而不是實際值。
這是第一頁的代碼:
Private Sub BindGrid()
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("dbconnection").ConnectionString)
con.Open()
Dim cmd As New SqlCommand("select distinct Name,assignment_id, Description ,cod from assignments
INNER Join crmsLecturerXCrsSection ON crmsLecturerXCrsSection.emp_key = assignments.emp_key
INNER Join CRMSStudentsXCrsSection ON CRMSStudentsXCrsSection.CrsSec_id = crmsLecturerXCrsSection.CrsSec_id
INNER JOIN CRMS_CourseXSection ON CRMS_CourseXSection.CrsSec_id = CRMSStudentsXCrsSection.CrsSec_id
INNER JOIN CRMSECTIONS ON CRMSECTIONS.SEC_ID = CRMS_CourseXSection.SEC_ID
left JOIN crmscourses ON crmscourses.crs_id = CRMS_CourseXSection.crs_id
INNER JOIN CRMS_CourseXSection cs ON CRMS_CourseXSection.SEC_ID = CRMSECTIONS.SEC_ID
INNER JOIN CRMSSEMESTER ON CRMSSEMESTER.SEM_ID = CRMS_CourseXSection.SEM_ID
where CRMSSEMESTER.SEM_ID='1'
and crmsLecturerXCrsSection.emp_key='436' and crmscourses.crs_desc='" Session("crs") "'", con)
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
da.Fill(dt)
Dim listIDs As New List(Of String)
Dim row As DataRow
For Each row In dt.Rows
listIDs.Add(row("assignment_id"))
Next
Session("assid") = listIDs
cmd.Connection = con
GridView1.DataSource = cmd.ExecuteReader()
GridView1.DataBind()
End Sub
這是第二頁:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = Session("assid").ToString()
Dim con1 As New SqlConnection(ConfigurationManager.ConnectionStrings("dbconnection").ConnectionString)
Dim cmd1 As New SqlCommand("select * from assignments where assignment_id ='" String.Join(",", Session("assid")) "'", con1)
End Sub
uj5u.com熱心網友回復:
你把aList(Of String)放進去Session("assid"),這就是你得到的東西。如果您呼叫ToString它,您將獲得型別名稱,這正是您所看到的,即"System.Collections.Generic.List1[System.String]"`。就像往常一樣,如果您想查看串列中的專案,那么您你需要先把這些專案拿出來。具體如何做取決于你想對這些專案做什么。例如,如果你只想在逗號分隔的串列中顯示專案,你可以這樣做:
Dim ids = DirectCast(Session("assid"), List(Of String))
Label1.Text = String.Join(", ", ids)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/443717.html
