Hi,
I have a treelist control with load on demand enabled. I need to expand items to first level for which i used " ExpandToLevel(1) " . Things were fine when i was having the older version of telerik. I recently upgraded it to the latest version and found this issue. On initial load things are fine. When i try to expand any item all the expanded levels and the buttons for expanding are lost and only the first level items are seen. For more information reg the problem pls check the sample code below.
Thanks,
Karthik
I have a treelist control with load on demand enabled. I need to expand items to first level for which i used " ExpandToLevel(1) " . Things were fine when i was having the older version of telerik. I recently upgraded it to the latest version and found this issue. On initial load things are fine. When i try to expand any item all the expanded levels and the buttons for expanding are lost and only the first level items are seen. For more information reg the problem pls check the sample code below.
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
RadTreeList1.ExpandToLevel(1);
}
}
protected
void
RadTreeList1_NeedDataSource(
object
sender, TreeListNeedDataSourceEventArgs e)
{
RadTreeList1.DataSource = GetDataTable(
"SELECT * FROM TestItems WHERE ParentID IS NULL"
,
null
);
}
protected
void
RadTreeList1_ChildItemsDataBind(
object
sender, TreeListChildItemsDataBindEventArgs e)
{
int
id = Convert.ToInt32(e.ParentDataKeyValues[
"ID"
].ToString());
SqlParameter param =
new
SqlParameter();
param.ParameterName =
"@ID"
;
param.Value = id;
e.ChildItemsDataSource = GetDataTable(
"SELECT * FROM TestItems WHERE ParentID = @ID"
, param);
}
private
DataTable GetDataTable(
string
query, SqlParameter param)
{
SqlConnection conn =
new
SqlConnection(ConnString);
SqlDataAdapter adapter =
new
SqlDataAdapter();
SqlCommand command =
new
SqlCommand(query, conn);
if
(param !=
null
)
{
command.Parameters.Add(param);
}
adapter.SelectCommand = command;
DataTable myDataTable =
new
DataTable();
conn.Open();
try
{
adapter.Fill(myDataTable);
}
finally
{
conn.Close();
}
return
myDataTable;
}
private
void
ConvertEmptyValuesToDBNull(Hashtable values)
{
List<
object
> keysToDbNull =
new
List<
object
>();
foreach
(DictionaryEntry entry
in
values)
{
if
(entry.Value ==
null
|| (entry.Value
is
String && String.IsNullOrEmpty((String)entry.Value)))
{
keysToDbNull.Add(entry.Key);
}
}
foreach
(
object
key
in
keysToDbNull)
{
values[key] = DBNull.Value;
}
}
private
void
ExecuteNonQuery(
string
commandText, Hashtable parameters)
{
SqlConnection conn =
new
SqlConnection(ConnString);
SqlCommand command =
new
SqlCommand(commandText, conn);
foreach
(DictionaryEntry entry
in
parameters)
{
command.Parameters.AddWithValue(entry.Key.ToString(), entry.Value);
}
conn.Open();
try
{
command.ExecuteNonQuery();
}
finally
{
conn.Close();
}
}
Thanks,
Karthik