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.
Syncfusion Feedback

Binding a String[] to DropDown in Grid?

Thread ID:

Created:

Updated:

Platform:

Replies:

125764 Sep 9,2016 06:01 PM UTC Sep 15,2016 03:08 PM UTC ASP.NET Web Forms 1
loading
Tags: DropDownList
Michael Lambert
Asked On September 9, 2016 06:01 PM UTC

Is it possible to bind just a simple String[] as a datasource for a Dropdown?

                string[] per= { "One", "Two", "Three" };

                var index = this.grdBudget.Columns.FindIndex(col => col.Field == "Period");   //dropdown control
                this.grdBudget.Columns.ElementAt(index).DataSource = per;

                grdBudget.DataSource = new BudgetEntities().Requests.ToList();
                grdBudget.DataBind();


PS in this short example I'm assigning 'per' statically but in my application I'll need to assign it dynamically, hence cannot just put the choices in the control def in xml.

Thanks,
Mike

Prasanna Kumar Viswanathan [Syncfusion]
Replied On September 15, 2016 03:08 PM UTC

Hi Michael, 
  
Thanks for contacting Syncfusion support. 
  
To bind an array of string as a dataSource for dropdown, use the editTemplate property of columns. Use editTemplate property we render the dropdown for particular column and bind the array of string as a datasource for the column. 
  
Find the code example and sample: 
  
  
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" > 
            
            <Columns> 
               --------------------------- 
            </Columns> 
  
            <EditSettings AllowEditing="True" AllowAdding="True" AllowDeleting="True"></EditSettings> 
            <ToolbarSettings ShowToolbar="True" ToolbarItems="add,edit,delete,update,cancel"></ToolbarSettings> 
        </ej:Grid>       
    </div> 
  
<script type="text/javascript"> 
        function create() { 
            return $("<input>"); 
        } 
  
        function write(args) { 
            var obj = $('#<%= OrdersGrid.ClientID %>').ejGrid('instance'); 
            var numbers = ["One", "Two", "Three"]; 
            args.element.ejDropDownList({ 
                width: "100%", 
                dataSource: numbers, 
                value: args.rowdata !== undefined ? args.rowdata["CustomerID"] : "" 
            }); 
        } 
  
        function read(args) { 
            return args.ejDropDownList("getValue"); 
        } 
    </script> 
</asp:Content> 
  
  
  
Regards, 
Prasanna Kumar N.S.V 
 


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

;