This is a migrated thread and some comments may be shown as answers.

DropdownTree set selected value when load from RadClientBinding

1 Answer 255 Views
DropDownTree
This is a migrated thread and some comments may be shown as answers.
Irene Alpen
Top achievements
Rank 1
Irene Alpen asked on 11 Jul 2016, 10:04 AM

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??? 

 

1 Answer, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 14 Jul 2016, 08:58 AM
Hi Irene,

I am not quite sure that I understand correctly your scenario. Could you, please, explain how you add new items to the RadDropDownTree? How do you edit them and what exactly is the problem with values?

Regards,
Veselin Tsvetanov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
DropDownTree
Asked by
Irene Alpen
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Share this question
or