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. Image for the cookie policy date

Bind Data from ObjectDataSource to ListBox

Hi,

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

 


1 Reply

AP Aruna P Syncfusion Team 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


Loader.
Live Chat Icon For mobile
Up arrow icon