this doesn't feel right
Private Sub drop_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles iqty.ItemDataBound
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim row As allowanceQtyQuery = CType(e.Item.DataItem, allowanceQtyQuery)
Dim unit = CType(e.Item.FindControl("Unit"), DropDownList)
Using db As New myContext
Dim u = db.getAllUnit(True)
unit.DataSource = u
unit.DataTextField = "descen"
unit.DataValueField = "unitid"
unit.DataBind()
End Using
unit.Text = row.Unit
End If
End Sub
because if I have let say 1000 items, it will declare 1000x the datacontext
how would you deal with this?
created this to be able to remove the "using db" part
Public ReadOnly Property listOfUnit() As List(Of Unit)
Get
If HttpContext.Current.Cache("unit") Is Nothing Then
Using db As New ODSTS
HttpContext.Current.Cache.Insert("unit", db.getAllUnit(True).ToList, Nothing, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(5))
End Using
End If
Return CType(HttpContext.Current.Cache("unit"), List(Of Unit))
End Get
End Property