We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Bind Data from ObjectDataSource to ListBox

Thread ID:

Created:

Updated:

Platform:

Replies:

113606 Oct 1,2013 02:58 PM UTC Oct 4,2013 01:59 PM UTC Orubase 1
loading
Tags: Orubase
Alaa Omer
Asked On October 1, 2013 02:58 PM UTC

Hi,

I need a help on how to bind data from objectdatasource to listbox

 


Aruna P [Syncfusion]
Replied On October 4, 2013 01:59 PM UTC

Hi Alaa,

Thanks for your interest in syncfusion products.

You can achieve your requirement by using following code snippets.

Model list data

 

//Creating object model for binding datas to list

public class Countries

    {

        public string Text { get; set; }

        public int id { get; set; }

        public List<Cities> Children { get; set; }

    }

public class Cities

    {

        ………..

    }

 

Controller

 

 

public ActionResult LBDatabindingReq()

        {

            var data = this.lstCountries();

            return View(data);

        }

 

[HttpPost]

        public ActionResult LBDatabindingReq(OrubaseProject36.Models.ListBoxParams args)

        {

            var data = this.lstCountries();

            return data.ListBoxHtmlAction<ControlList>(this.iDataBound);

        }

[ChildActionOnly]

        public void iDataBound(DataBindingFactory<ListBoxItem> data)

        {

            data.MapTo<Countries>(binding =>

            {

                binding.ItemDataBound((item, nd) =>

                {

                    item.Text = nd.Text;

                    item.PrimaryKeyValue = nd.id;

                })

                .Children(nd => nd.Children);

            });

            data.MapTo<Cities>(binding =>

            {

                binding.ItemDataBound((item, snd) =>

                {

                    item.Text = snd.Text;

                    item.PrimaryKeyValue = snd.id;

                });

              

            });

          

        }

 

 

View

@{

       Html.Orubase().ListBox("lbDatabinding").Title("DataBinding")

         .BindDataSource(Model, map =>

         {

             map.MapTo<OrubaseProject36.Models.Countries>(binding =>

             {

                 binding.ItemDataBound((item, nd) =>

                 {

                     item.Text = nd.Text;

                   

                     item.PrimaryKeyValue = nd.id;

                 })

                .Children(nd => nd.Children);

             });

             map.MapTo<OrubaseProject36.Models.Cities>(binding =>

             {

                 binding.ItemDataBound((item, snd) =>

                 {

                     item.Text = snd.Text;

                 });

             });

         })

 

         .Render();

    }

We have prepared simple sample for your reference and attached in the below link,

SampleDemo ().zip

Please try this and get back to us if you have any queries.  

Regards,
Aruna


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;