project using RadClientDataSource to binding RadDropdownTree control using WebService WCF. Load data is ok.
This my code:
.aspx:
<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
<telerik:RadClientDataSource ID="RadClientDataSource1" runat="server"
AllowBatchOperations="True">
<ClientEvents OnCustomParameter="ParameterMap" OnDataParse="Parse" />
<DataSource>
<WebServiceDataSourceSettings BaseUrl="UserInfoService.svc/">
<Select Url="GetDonVis" DataType="JSON" RequestType="Post" ContentType="application/json; charset=utf-8" />
</WebServiceDataSourceSettings>
</DataSource>
<Schema>
<Model>
<telerik:ClientDataSourceModelField FieldName="MaDonVi" DataType="String" />
<telerik:ClientDataSourceModelField FieldName="TenDonVi" DataType="String" />
<telerik:ClientDataSourceModelField FieldName="ParentId" DataType="String" />
</Model>
</Schema>
</telerik:RadClientDataSource>
<telerik:RadDropDownTree RenderMode="Classic" EnableFiltering="true" ID="RadDropDownTree1" runat="server"
DropDownSettings-Height="220px" Width="100%" DropDownSettings-CloseDropDownOnSelection="true"
ClientDataSourceID="RadClientDataSource1" DataTextField="TenDonVi"
DataValueField="MaDonVi" DataFieldID="MaDonVi"
DataFieldParentID="ParentId" Skin="Office2007">
<CollapseAnimation Type="None" />
</telerik:RadDropDownTree>
WebService:
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
public CustomersResult GetDonVis()
{
//Doc data tu DB
SqlConnection sqlConnection = new SqlConnection();
try
{
sqlConnection.ConnectionString = "SERVER=localhost;Database=LongBien;UID=sa;PWD=abcde12345-;";
sqlConnection.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM tblDmDonVi;", sqlConnection);
DataTable dataTable = new DataTable("DonVi");
da.Fill(dataTable);
da.Dispose();
List<ServiceDonVi> result = new List<ServiceDonVi>();
foreach (DataRow dataRow in dataTable.Rows)
{
ServiceDonVi donVi = new ServiceDonVi();
donVi.MaDonVi = dataRow["MaDonVi"].ToString();
donVi.TenDonVi = dataRow["TenDonVi"].ToString();
if (dataRow["ParentId"] != DBNull.Value)
{
donVi.ParentId = dataRow["ParentId"].ToString();
}
result.Add(donVi);
}
dataTable.Dispose();
CustomersResult a = new CustomersResult();
a.Data = result;
a.Count = 100;
return a;
}
catch (Exception exception)
{
throw;
}
finally
{
sqlConnection.Close();
sqlConnection.Dispose();
}
}
But I has problem:
1. When addnew data item -> save data in database is ok. (Example: value selected = 5)
2. When edit this item, how to set selected item keep old value (value = 5) has save in database???