Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
145
Binding to a Stored Procedure
posted

Hi, I'm trying to populate a WebDataTree using a Stored Procedure, but I'm having difficulty. The example in the "StartupSamples" project uses hard-coded nodes defined in the .aspx page (which doesn't really help my cause) and the examples/forums are fairly thin on the ground. I've also tried looking for a tutorial without much luck. I've attached my current .aspx code below, but allow me to explain the issues...

The .aspx page currently contains two WebDataTrees, one bound to a standard SQLDataSource ("WebDataTreeBusinessAreas"), the other bound to a WebHierarchicalDataSource ("WebDataTreeResourceGroups"). I'm not sure if using a WebHierarchicalDataSource is the correct route to take but it seems like a logical step - please correct me if I'm wrong. Let me take each WebDataTree at a time and explain my difficulties (you'll have to bear with me, this is the first time I've worked with trees)...

"WebDataTreeBusinessAreas": this tree is bound to a standard SQLDataSource ("dsBusinessAreaList"). I've been able to successfully bind the tree nodes to the tree and have it display the data correctly (in this instance, all the business areas returned by the stored procedure - "BusinessAreDesc"). However, I'm unsure as to how to then display the related children nodes (which are returned by the "dsProcessList" SQLDataSource, containing all of the business area's processes). Note that the "dsBusinessAreaList" and "dsProcessList" datasources relate data via the "BusinessAreaID" column.

"WebDataTreeResourceGroups": this tree is bound to a WebHierarchicalDataSource which I hoped would make it easier to build the tree parent/child nodes. However, whilst it's certainly populating the correct number of parents & associated child nodes, I'm having trouble binding the actual data to the nodes. I'm able to populate the very first parent node but I'm unable to bind the remain parents nodes or any of the child nodes (including those associated with the first parent node).

If someone could review the .aspx code I have currently, then offer some guildance, I would be supremely grateful.

<%@ Page Language="VB" Theme="Theme1" AutoEventWireup="false" CodeFile="BusinessAreaTreeInfragistics.aspx.vb" Inherits="Brava.Content_Tools_BusinessAreaTreeInfragistics" %>

<%@ Register Assembly="Infragistics2.Web.v11.1, Version=11.1.20111.1006, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
    Namespace="Infragistics.Web.UI.NavigationControls" TagPrefix="ig" %>

    <%@ Register assembly="Infragistics2.Web.v11.1, Version=11.1.20111.1006, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.Web.UI.DataSourceControls" tagprefix="ig" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html id="Html1" runat="server" dir="<%$ Resources: SiteResources, Direction %>" xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
 <title>Business Area Tree</title>
 <link href="../../stylesheets/stylesheet.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">


    </script>
</head>
<body>
    <form id="Form1" method="post" runat="server" style="left: 55px;">

        <asp:ScriptManager ID="ScriptManager1" runat="server"/>
       
        <asp:CheckBox ID="ChkIncludeInactive" runat="server"
            Text=" Include Inactive Items" AutoPostBack="true" Font-Names="Arial"
            Font-Size="Small" ForeColor="#FF3300" />
        <br />
        <br />


    <ig:WebDataTree ID="WebDataTreeBusinessAreas" runat="server" Height="300px" Width="200px" DataSourceID="dsBusinessAreaList">
        <DataBindings>
            <ig:DataTreeNodeBinding TextField="BusinessAreaDesc" ValueField="BusinessAreaID" />
        </DataBindings>
    </ig:WebDataTree>
   
        <asp:SqlDataSource runat="server" ID="dsBusinessAreaList" ProviderName="System.Data.SqlClient" connectionString="Password=password;Persist Security Info=True;User id=BRAVAUser;Initial Catalog=Brava_1_0_0;Data Source=badgervs1"
         SelectCommand="BusinessAreaList" SelectCommandType="StoredProcedure" >
            <SelectParameters>
                <asp:Parameter Name="ShowActiveOnly" Type="Boolean" DefaultValue="true"/>
                <asp:Parameter Name="ShowBlankentry" Type="Boolean" DefaultValue="false"/>
            </SelectParameters>
        </asp:SqlDataSource>

        <asp:SqlDataSource runat="server" ID="dsProcessList" ProviderName="System.Data.SqlClient" connectionString="Password=password;Persist Security Info=True;User id=BRAVAUser;Initial Catalog=Brava_1_0_0;Data Source=badgervs1"
         SelectCommand="ProcessList" SelectCommandType="StoredProcedure" >
            <SelectParameters>
                <asp:Parameter Name="BusinessAreaID" Type="Boolean"/>
                <asp:Parameter Name="ShowActiveOnly" Type="Boolean" DefaultValue="true"/>
                <asp:Parameter Name="ShowBlankentry" Type="Boolean" DefaultValue="false"/>
            </SelectParameters>
        </asp:SqlDataSource>


    <ig:WebDataTree ID="WebDataTreeResourceGroups" runat="server" Height="300px" Width="200px" DataSourceID="whdResourceGroupList">
        <DataBindings>
            <ig:DataTreeNodeBinding TextField="ResourceGroupDesc" ValueField="ResourceGroupID" ></ig:DataTreeNodeBinding>
        </DataBindings>
    </ig:WebDataTree>

        <ig:WebHierarchicalDataSource ID="whdResourceGroupList" runat="server">
            <DataRelations>
                <ig:DataRelation
                    ParentColumns="ResourceGroupID" ParentDataViewID="dvResourceGroupList"
                    ChildColumns="ResourceGroupID" ChildDataViewID="dvResourceGroupMemberList" />
                </DataRelations>
            <DataViews>
                <ig:DataView ID="dvResourceGroupList" DataSourceID="dsResourceGroupList" />
                <ig:DataView ID="dvResourceGroupMemberList" DataSourceID="dsResourceGroupMemberList" />        
            </DataViews>
  </ig:WebHierarchicalDataSource> 

        <asp:SqlDataSource runat="server" ID="dsResourceGroupList" ProviderName="System.Data.SqlClient" connectionString="Password=password;Persist Security Info=True;User id=BRAVAUser;Initial Catalog=Brava_1_0_0;Data Source=badgervs1"
      SelectCommand="ResourceGroupList" SelectCommandType="StoredProcedure"
            UpdateCommand="ResourceGroupAmend" UpdateCommandType="StoredProcedure"
            InsertCommand="ResourceGroupAdd" InsertCommandType="StoredProcedure" >
            <SelectParameters>
                <asp:Parameter Name="ShowActiveOnly" Type="Boolean" DefaultValue="true"/>
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="ResourceGroupID" Type="Int32" />
                <asp:Parameter Name="ResourceGroupDesc" Type="String" />
                <asp:Parameter Name="Active" Type="Boolean" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="ResourceGroupDesc" Type="String" />
                <asp:Parameter Name="Active" Type="Boolean" />           
            </InsertParameters>
  </asp:SqlDataSource>

  <asp:SqlDataSource runat="server" ID="dsResourceGroupMemberList" ProviderName="System.Data.SqlClient" connectionString="Password=password;Persist Security Info=True;User id=BRAVAUser;Initial Catalog=Brava_1_0_0;Data Source=badgervs1"
      SelectCommand="ResourceGroupMemberList" SelectCommandType="StoredProcedure"
            DeleteCommand="ResourceGroupMemberRemove" DeleteCommandType="StoredProcedure" >
            <DeleteParameters>
                <asp:Parameter Name="ResourceGroupID" Type="Int32"/>
                <asp:Parameter Name="ResourceID" Type="Int32"/>
            </DeleteParameters>
   </asp:SqlDataSource>

 </form>
</body>
</html>

  • 49378
    Suggested Answer
    posted

    Hi Martin,

    In order to operate correctly, the WebDataTree requires a hierarchical data source. Therefore a WebHierarchicalDataSource would be a correct approach for both of your trees.

    For your first tree - "WebDataTreeBusinessAreas":

    As far as I can see you want to have a parent node which is bound to your dsBusinessAreaList sql data source. After that, you want to add a child node which is bound to dsProcessList. 

    The WebDataTree can have only one data source, therefore to achieve your hierarchical structure you need to use a WebHierarchicalDataSource in which dsBusinessAreaList is a parent node and dsProcessList is a child node. You would also need to provide some relation between the two so the parent and child nodes can be matched (e.g. on some ID columns).

    Regarding your second question - binding the actual data to the nodes:

    In order to bind data to a node, first you need to set the Key property of that node. For instance :

                <ig:DataTreeNode Text="Root Node" Key="Root">
                </ig:DataTreeNode>

    Afterwards you need to set the KeyField property in the data bindings to the respective node key. For example:

            <DataBindings>
                <ig:DataTreeNodeBinding TextField="ProductName" ValueField="CategoryName" KeyField = "Root"  />
            </DataBindings>

    Upon undergoing these procedures, the tree should display your data correctly.

    You can find a sample illustrating data binding to a WebDataTree at:

    http://samples.infragistics.com/aspnet/Samples/WebDataTree/Data/DataBinding/Default.aspx?cn=data-tree&sid=008acd5c-8589-419d-a37f-c454f52ad737

    Please contact me if you have any questions.

    Petar Ivanov
    Developer Support Engineer
    Infragistics, Inc.
    http://es.infragistics.com/support