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

Grid/Editing/Inline Editing - DropDownList

Hi

It's possible bind data  DropDownlist in grid ?

I try that but unable to bind the data, Please find the attachment


Thanks
Pratheep 



Attachment: Inline_Editing_482ad953.rar

5 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team September 14, 2015 10:51 AM UTC

Hi Pratheep,

Thanks for contacting Syncfusion support.

Yes it is possible to bind the dataSource for the dropdown list to the particular column and we suggest you to bind the dataSource in the server side. We have bound the dataSource for dropdown list and the dataSource passed must be in the value and text property as in the below code example,

Please find the following code example and sample,

public partial class Default : System.Web.UI.Page

    {

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

        List<Orders> order = new List<Orders>();

        protected void Page_Load(object sender, EventArgs e)

        {

            for (int i = 1; i < 10; i++)

            {

                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()

        {

            int code = 10000;

            for (int i = 1; i < 10; i++)

            {

                order.Add(new Orders(code + 1, "Andreas", i + 0, 2.3 * i, new DateTime(1991, 05, 15), "Berlin"));

                order.Add(new Orders(code + 2, "Frank", i + 2, 3.3 * i, new DateTime(1990, 04, 04), "Madrid"));

                order.Add(new Orders(code + 3, "Willi", i + 1, 4.3 * i, new DateTime(1957, 11, 30), "Cholchester"));

                order.Add(new Orders(code + 4, "Horst", i + 3, 5.3 * i, new DateTime(1930, 10, 22), "Marseille"));

                order.Add(new Orders(code + 5, "Manfred", i + 4, 6.3 * i, new DateTime(1953, 02, 18), "Tsawassen"));

                code += 5;

            }

            this.Grid.DataSource = order;

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

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

            this.Grid.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; }

    }
  }



Sample Link: http://www.syncfusion.com/downloads/support/forum/120217/ze/Sample1743431349

If we misunderstood your query, please send more details about the requirement that will help to provide a better solution.


Regards,
Prasanna Kumar N.S.V


PR Pratheep September 17, 2015 04:08 AM UTC

Hi

Thanks, working fine 

Pratheep


PR Pratheep September 17, 2015 05:07 PM UTC

Hi


I click on grid for edit records -  the customers dropdown is shown with the customers list but after selecting any customer and click on save then the value of selected customer is shown in grid instead of text.




public partial class Default : System.Web.UI.Page

    {

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

        List<Orders> order = new List<Orders>();

        protected void Page_Load(object sender, EventArgs e)

        {

            for (int i = 1; i < 10; i++)

            {

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

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

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

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

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

            }

            BindDataSource();

        }


        private void BindDataSource()

        {

            int code = 10000;

            for (int i = 1; i < 10; i++)

            {

                order.Add(new Orders(code + 1, "Andreas", i + 0, 2.3 * i, newDateTime(1991, 05, 15), "Berlin"));

                order.Add(new Orders(code + 2, "Frank", i + 2, 3.3 * i, newDateTime(1990, 04, 04), "Madrid"));

                order.Add(new Orders(code + 3, "Willi", i + 1, 4.3 * i, newDateTime(1957, 11, 30), "Cholchester"));

                order.Add(new Orders(code + 4, "Horst", i + 3, 5.3 * i, newDateTime(1930, 10, 22), "Marseille"));

                order.Add(new Orders(code + 5, "Manfred", i + 4, 6.3 * i, newDateTime(1953, 02, 18), "Tsawassen"));

                code += 5;

            }

            this.Grid.DataSource = order;

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

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

            this.Grid.DataBind();

        }


        [Serializable]

        


        public class Customer

        {

            public Customer()

            {


            }


        public Customer (string text, string value)

        {

            this.text = text;

            this.value = value;

        }

            public string text { getset; }

            public string value { getset; }

    }
  }


Pratheep





MF Mohammed Farook J Syncfusion Team September 18, 2015 12:38 PM UTC

Hi Pratheep,

We have validated your reported issue and we will update with in one business day ( 21th September 2015).

Regards,
J.Mohammed Farook


PK Prasanna Kumar Viswanathan Syncfusion Team September 21, 2015 06:42 AM UTC

Hi Pratheep,

To store the selected text in the dropdown, we can use foreignKey column feature of the Grid. 

Foreign key is a field in relational table that matches the specific key columns of another table.

Please find the following  code example and sample,

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

           <EditSettings AllowEditing="True" AllowAdding="True" AllowDeleting="True"></EditSettings>

           <ToolbarSettings ShowToolbar="True" ToolbarItems="add,edit,delete,update,cancel"></ToolbarSettings>

            <ClientSideEvents EndEdit="endedit" />

            <Columns>

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

                    <ValidationRule>

                        <ej:KeyValue Key="required" Value="true" />

                        <ej:KeyValue Key="number" Value="true" />

                    </ValidationRule>

                </ej:Column>

                <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="80">

                     <ValidationRule>

                        <ej:KeyValue Key="required" Value="true" />

                        <ej:KeyValue Key="minlength" Value="3" />

                    </ValidationRule>

                </ej:Column>

                <ej:Column Field="EmployeeID" HeaderText="Employee Name" ForeignKeyField="EmployeeID"

                    ForeignKeyValue="FirstName" TextAlign="Left" Width="90" />

                <ej:Column Field="Freight" HeaderText="Freight" TextAlign="Right" Width="75" Format="{0:C}" EditType="Numeric">

                    <NumericEditOptions DecimalPlaces="2"></NumericEditOptions>

                </ej:Column>

                <ej:Column Field="ShipCity" HeaderText="Ship City" Width="80" />

                <ej:Column Field="ShipCountry" HeaderText="Ship Country" Width="80" />

            </Columns>
        </ej:Grid>
---------------------------------------------------------------------

{

                employee.Add(new Employee(1, "Michael"));

                employee.Add(new Employee(2, "Anne"));

                employee.Add(new Employee(3, "Janet"));

                employee.Add(new Employee(4, "Andrew"));

                employee.Add(new Employee(5, "Margaret"));

                employee.Add(new Employee(6, "Nancy"));

                employee.Add(new Employee(7, "Robert"));

                employee.Add(new Employee(8, "Laura"));

                employee.Add(new Employee(9, "Steven"));

                employee.Add(new Employee(10, "James"));

                employee.Add(new Employee(11, "Smith"));

                employee.Add(new Employee(12, "Jhonson"));

                employee.Add(new Employee(13, "George"));

           

        }

public class Employee

        {

            public Employee()

            {


            }

            public Employee(int EmployeeId, string FirstName)

            {

                this.EmployeeID = EmployeeId;

                this.FirstName = FirstName;

            }

            public int EmployeeID { get; set; }

            public string FirstName { get; set; }

        }


Sample : http://www.syncfusion.com/downloads/support/forum/120217/ze/Sample-542423917

Please refer the below links for more information on the foreignkeycolumn feature

OnlineDocumentation Link: http://help.syncfusion.com/aspnet/grid/columns#foreign-key-columns

Online Sample Link: http://asp.syncfusion.com/demos/web/grid/foreignkeycolumn.aspx

Regards,
Prasanna Kumar N.S.V

Loader.
Live Chat Icon For mobile
Up arrow icon