DropdownTree set selected value when load from RadClientBinding

2 posts, 0 answers
  1. Irene Alpen
    Irene Alpen avatar
    19 posts
    Member since:
    Jul 2004

    Posted 11 Jul Link to this post

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

     

  2. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    283 posts

    Posted 14 Jul Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top