- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
Lazy loading: treeview using llblgen 2.6 (C# Webforms)
Posts
Posts: 1
Joined: 25-Oct-2012
Joined: 25-Oct-2012
# Posted on: 25-Oct-2012 15:07:37
Hi,
I have a tree view that is pulling back locations, i would like to only fetch items when the user has clicked to expand a parent in a asp.net webforms treeView, does llblgen 2.6 support lazy loading in this manner ? & how would you go about doing this ? here is my code at the moment.
Currently it all loads at once as seen in this image link http://i49.tinypic.com/2w2r4ub.jpg
ASPX
<asp:Panel ID="pnlTree" runat="server" CssClass="pnlTreeStyle" meta:resourcekey="pnlTreeResource1">
<asp:TreeView onclick="BeginRequestHandler()" ID="treeLocations" runat="server" Width="100%" Height="99%"
OnSelectedNodeChanged="lstLocations_SelectedIndexChanged" OnTreeNodeExpanded="PopulateTreeNode" Style="overflow: auto" meta:resourcekey="treeLocationsResource1">
<SelectedNodeStyle BackColor="#3333FF" ForeColor="White" />
</asp:TreeView>
</asp:Panel>
ASPX.CS
private void FillLocationsList()
{
IcLocationsEntity location = Service.ICLocation_GetLocation(currentlocation);
TreeNode NewNode = new TreeNode(location.LocationDesc, location.LocationId.ToString());
treeLocations.Nodes.Add(NewNode);
BuildLocationTree(NewNode.ChildNodes, IC_WebAppCommon.GetPersonLocation());
}
private void BuildLocationTree(TreeNodeCollection nodes, Int32 IntParent)
{
try
{
Int32 LocationID;
String LocationDesc;
EntityCollection<IcLocationsEntity> children = Service.ICLocation_GetChildrenLocations(IntParent); //v1.0.5 WW
//no child nodes, exit function
if (children.Count == 0) return;
foreach (IcLocationsEntity child in children)
{
// step 1
LocationID = child.LocationId;
// step 2
LocationDesc = child.LocationDesc;
// step 3
TreeNode NewNode = new TreeNode(LocationDesc, LocationID.ToString());
// step 4
nodes.Add(NewNode);
NewNode.ToggleExpandState();
// step 5
BuildLocationTree(NewNode.ChildNodes, LocationID);
}
}
catch (Exception Excpt)
{
throw new Exception("BuildLocationTree() " + Excpt.Message);
}
}
SERVICE
public static IcLocationsEntity GetLocation(string pConnectionString, Int32 pLocationID)
{
IcLocationsEntity icLocationEntity = new IcLocationsEntity();
try
{
RelationPredicateBucket predBkt = new RelationPredicateBucket();
IPredicateExpression predExp = new PredicateExpression();
predExp.Add(IcLocationsFields.LocationId == pLocationID);
predExp.Add(IcLocationsFields.Deleted == false);
predBkt.PredicateExpression.Add(predExp);
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
// adapter.FetchEntityCollection(
adapter.ConnectionString = pConnectionString;
if (!(adapter.FetchEntityUsingUniqueConstraint(icLocationEntity, predBkt.PredicateExpression)))
{
icLocationEntity = null;
}
}
}
catch (Exception ex)
{
throw new Exception("(e)IC_CommonDLL - ICLocationFunctions:GetLocation() " + ex.Message);
}
return icLocationEntity;
}
public static EntityCollection<IcLocationsEntity> GetChildrenLocations(string pConnectionString, Int32 pLocationID)
{
EntityCollection<IcLocationsEntity> MyIcLocations = new EntityCollection<IcLocationsEntity>();
try
{
ISortExpression sorter = new SortExpression();
sorter.Add(IcLocationsFields.LocationDesc | SortOperator.Ascending);
RelationPredicateBucket predBkt = new RelationPredicateBucket();
IPredicateExpression predExp = new PredicateExpression();
predExp.Add(IcLocationsFields.Deleted == false);
predExp.Add(IcLocationsFields.ParentId == pLocationID);
predBkt.PredicateExpression.Add(predExp);
using (DataAccessAdapter MyAdapter = new DataAccessAdapter())
{
MyAdapter.ConnectionString = pConnectionString;
MyAdapter.FetchEntityCollection(MyIcLocations, predBkt, 0, sorter);
}
}
catch (Exception ex)
{
throw new Exception("(e)IC_CommonDLL - ICLocationFunctions:GetChildrenLocations() " + ex.Message);
}
return MyIcLocations;
}
# Posted on: 25-Oct-2012 18:21:24
You use adapter, which doesn't support lazy loading, but you can build this in yourself: when the expand event for the node occurs, simply fetch the new data with a new adapter instance.