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.
Unfortunately, activation email could not send to your email. Please try again.

Bind Data from ObjectDataSource to ListBox

Thread ID:

Created:

Updated:

Platform:

Replies:

113606 Oct 1,2013 10:58 AM Oct 4,2013 09:59 AM Orubase 1
loading
Tags: Orubase
Alaa Omer
Asked On October 1, 2013 10:58 AM

Hi,

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

 


Aruna P [Syncfusion]
Replied On October 4, 2013 09:59 AM

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.

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.

;