I had a setup where I had a datalist of course listings, and when the items were created I went out to a remote sql server and retrieved the faculty for each course. But, that seems to take too long to load, so I thought it would be faster to go get all the data at once on page load and then filter with data views. But, I can't seem to get there. I tested on a datagrid outside the datalist and it populates with 3 rows fine. (Number one - is my assumption correct? Number two - what am I doing wrong? Is the Public Data.dataView not available when I'm trying to call it?)
It stops on the line
'dv.RowFilter = "eid=" & myEID.ToString
with the error: Object reference not set to an instance of an object.
If I comment out the line, I get no datagrids.
Imports dsList
Partial Class orpce_hcClasses
Inherits System.Web.UI.Page
Public ds As New Data.DataSet
Public myFacView As Data.DataView
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim myList As dsSql = New dsSql() ''''instantiate the function to get dataset
Dim myView As Data.DataView
Dim myStr As String = ""
ds = myList.dsListAll(go get the initial course datalist dataset)
If ds.Tables("list").Rows.Count > 0 Then
myView = ds.Tables("list").DefaultView
dlList.DataSource = myView
myView.Sort = "startSort"
dlList.DataBind()
If ds.Tables("list").Rows.Count > 0 Then
Dim i As Integer
For i = 0 To ds.Tables("list").Rows.Count - 1
myStr &= ds.Tables("list").Rows(i)("eid").ToString & ","
Next
myStr = Left(myStr, Len(myStr) - 1)
End If
ds = myList.dsListFac(myStr)
myFacView = New Data.DataView
myFacView = ds.Tables("faculty").DefaultView
End If
End If
End Sub
Protected Sub dlList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlList.ItemDataBound
Dim myEID As String = Convert.ToInt32(CType(e.Item.FindControl("txtEID"), TextBox).Text)
Dim dv As Data.DataView
Dim dg As DataGrid = CType(e.Item.FindControl("dgFac"), DataGrid)
dv = myFacView
'dv.RowFilter = "eid=" & myEID.ToString
dg.DataSource = dv
dg.DataBind()
End Sub
!--removed tag-->
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).