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
close icon

Fill dropdownlist that is inside grid cell with another datasource

Hi, I have a grid and that has some EditType="DropDown" columns.

I would like to fill these dropdowns with data from another datasource besides 
the grid one. Any clue?



3 Replies

BM Balaji Marimuthu Syncfusion Team March 12, 2015 12:37 PM UTC

Hi Artur,

Thanks for using Syncfusion Products.

We have achieved your requirement by using the DataSource property in Grid columns. Please find the sample and the code snippet.

Sample: 118480-dropdown.zip

[Default]

  <ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" >

          

            <Columns>

                <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" TextAlign="Right" Width="90"/>

                <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="90" EditType="Dropdown" />

               

              . . . . . . .

           </Columns>

           

        </ej:Grid>

[Default.aspx]

        List<Customer> customers = new List<Customer>();

        protected void Page_Load(object sender, EventArgs e)

        {

            customers.Add(new Customer() { text = "Andreas", value = "Andreas" });

            customers.Add(new Customer() { text = "Frank" ,  value = "Frank" });

            customers.Add(new Customer() { text = "Willi" ,  value = "Willi" });

            customers.Add(new Customer() { text = "Horst" ,  value = "Horst" });

            customers.Add(new Customer() { text = "Manfred",  value = "Manfred" });

            BindDataSource();            

        }

        private void BindDataSource()

        {

            

            . . . . . . .           

           this.OrdersGrid.DataSource = order;

            var index = this.OrdersGrid.Columns.FindIndex(col => col.Field == "CustomerID");

            this.OrdersGrid.Columns.ElementAt(index).DataSource = customers;

       

            this.OrdersGrid.DataBind();

        }

        [Serializable]

        public class Customer

        {

            public Customer()

            {

            }

            public Customer(string text, string value)

            {

                this.text = text;

                this.value = value;

            }

            public string text { get; set; }

            public string value { get; set; }

        }

    }

By using the DataSource property in Grid columns, we can bind the datasource to the columns in editmode.

Please let us know If you have any queries.

Regards,

Balaji Marimuthu




AR Artur March 13, 2015 01:19 PM UTC

This was very very useful! Thanks!

But I'd like to say that I found another way to do it using 
a custom template with an independent dropdown ;)

Thanks anyway



BM Balaji Marimuthu Syncfusion Team March 16, 2015 02:23 PM UTC

Hi Artur,

Thank you for the update.

Please let us know if you need any further assistance.

Thanks,

Balaji Marimuthu

Loader.
Live Chat Icon For mobile
Up arrow icon