I have a RadTreeView where the nesting is not happening how I'd like. I think it is confusing values from the ParentDataKey and DataKey. I am loading data from two tables - ApplicationParent and Application. The Application table has a ParentId column that is a foreign key to ApplicationParent.
There is one record that I'm having trouble with. See the attached screenshot "treelist data.jpg". There is an app with a ParentID of 100. There also exists an Application with an AppId of 100 and an ApplicationParent record with a ParentId of 100. In the UI, the nesting occurs as shown in the attached screenshots "treelist ui 1.jpg" and "treelist ui 2.jpg". What I want is for the application "UBH PIF Tracking" to be nested underneath the parent app of the same name.
Here is my code for the TreeList markup and for loading the data:
How do you suggest I solve this problem? Right now my only idea is to modify the DB to ensure that there are no ApplicationParents that have a ParentId that is equal to an Application.AppId.
There is one record that I'm having trouble with. See the attached screenshot "treelist data.jpg". There is an app with a ParentID of 100. There also exists an Application with an AppId of 100 and an ApplicationParent record with a ParentId of 100. In the UI, the nesting occurs as shown in the attached screenshots "treelist ui 1.jpg" and "treelist ui 2.jpg". What I want is for the application "UBH PIF Tracking" to be nested underneath the parent app of the same name.
Here is my code for the TreeList markup and for loading the data:
<
telerik:RadTreeList
ID
=
"lstApplications"
runat
=
"server"
AllowSorting
=
"True"
ParentDataKeyNames
=
"ParentID"
DataKeyNames
=
"AppID"
OnNeedDataSource
=
"lstApplications_NeedDataSource"
AutoGenerateColumns
=
"False"
AllowPaging
=
"True"
PageSize
=
"15"
TabIndex
=
"3"
>
<
clientsettings
>
<
Selecting
AllowItemSelection
=
"True"
/>
<
ClientEvents
OnItemClick
=
"OnItemClick"
OnItemDblClick
=
"OnItemDblClick"
/>
<
selecting
allowitemselection
=
"True"
/>
</
clientsettings
>
<
Columns
>
<
telerik:TreeListBoundColumn
DataField
=
"AppID"
HeaderText
=
"AppID"
UniqueName
=
"AppID"
Visible
=
"false"
ReadOnly
=
"True"
/>
<
telerik:TreeListBoundColumn
DataField
=
"Name"
HeaderText
=
"Application"
ItemStyle-Width
=
"20%"
UniqueName
=
"Name"
ReadOnly
=
"True"
>
<
HeaderStyle
Width
=
"20%"
/>
<
ItemStyle
Width
=
"20%"
/>
</
telerik:TreeListBoundColumn
>
<
telerik:TreeListBoundColumn
DataField
=
"Description"
HeaderText
=
"Description"
UniqueName
=
"Description"
ReadOnly
=
"True"
/>
</
Columns
>
</
telerik:RadTreeList
>
public class MyData
{
public static List<
MyItem
> GetData(String prefixText)
{
var mergedList = GetParentData(prefixText).Union(GetChildData(prefixText)).ToList();
return mergedList;
//return GetChildData(prefixText);
}
public static List<
MyItem
> GetParentData(String prefixText)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DataAccess.Properties.Settings.SecureConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("SelApplicationsParent", cn);
cmd.CommandType = CommandType.StoredProcedure;
if (!prefixText.Equals(String.Empty))
{
cmd.Parameters.AddWithValue("nrows", 30); //Set results limit to prevent typing lag.
cmd.Parameters.AddWithValue("term", ("%" + prefixText + "%")); //Set filter by name
}
List<
MyItem
> list = new List<
MyItem
>();
cn.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (dr.HasRows)
{
while (dr.Read())
{
string AppID = dr["ParentID"].ToString();
string ParentID = ""; //dr["ParentID"].ToString();
string Name = dr["Name"].ToString();
string Description = dr["Description"].ToString();
list.Add(new MyItem(AppID, Name, Description, ParentID));
}
}
dr.Close();
return list;
}
public static List<
MyItem
> GetChildData(String prefixText)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DataAccess.Properties.Settings.SecureConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("SelApplicationsChild", cn);
cmd.CommandType = CommandType.StoredProcedure;
if (!prefixText.Equals(String.Empty))
{
cmd.Parameters.AddWithValue("NRows", 30); //Set results limit to prevent typing lag.
cmd.Parameters.AddWithValue("Parent", ("%" + prefixText + "%"));
}
List<
MyItem
> list = new List<
MyItem
>();
cn.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (dr.HasRows)
{
while (dr.Read())
{
string AppID = dr["AppID"].ToString();
string ParentID = dr["ParentID"].ToString();
string Name = dr["Name"].ToString();
string Description = dr["Description"].ToString();
list.Add(new MyItem(AppID, Name, Description, ParentID));
}
}
dr.Close();
return list;
}
}
public class MyItem
{
public string AppID { get; set; }
public string ParentID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public MyItem(string appID, string name, string description, string parentID)
{
AppID = appID;
ParentID = parentID;
Name = name;
Description = description;
}
}
protected void lstApplications_NeedDataSource(object sender, TreeListNeedDataSourceEventArgs e)
{
lstApplications.DataSource = MyData.GetData(txtFilter.Text);
}
How do you suggest I solve this problem? Right now my only idea is to modify the DB to ensure that there are no ApplicationParents that have a ParentId that is equal to an Application.AppId.