Articles in this section
Category / Section

How to fetch data from Code behind for dropdown edit field in Grid?

1 min read

In some cases (Editing/Adding) we can bind external data to dropdown edit field columns in Grid by means of code behind.

 

Solution:

 

Using the DataSource property of Grid Column, we can bind external data in the dropdown column of Grid. DataSource for the dropdown column must be given in form of text and value pair or else fields must be enabled to DropDownList.

 

Refer our below link for our API reference

 

https://help.syncfusion.com/cr/cref_files/aspnet/Syncfusion.EJ.Web~Syncfusion.JavaScript.Web.DropDownList~DropDownListFields.html

 

https://help.syncfusion.com/cr/cref_files/aspnet/Syncfusion.EJ.Web~Syncfusion.JavaScript.Web.DropDownList~Text.html

https://help.syncfusion.com/cr/cref_files/aspnet/Syncfusion.EJ.Web~Syncfusion.JavaScript.Web.DropDownList~Value.html  

 

Aspx

 

<ej:Grid ID="Grid1" runat="server" AllowPaging="True">
     <ClientSideEvents EndAdd="endAdd" EndDelete="endDelete" 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" TextAlign="Left" Width="90">
              <ValidationRule>
                   <ej:KeyValue Key="required" Value="true" />
                   <ej:KeyValue Key="minlength" Value="3" />
              </ValidationRule>
         </ej:Column>
         <ej:Column Field="Freight" HeaderText="Freight" TextAlign="Right" Width="80" Format="{0:C}" EditType="NumericEdit">
              <NumericEditOptions DecimalPlaces="2"></NumericEditOptions>
         </ej:Column>
         <ej:Column Field="ShipName" HeaderText="ShipName" Width="110"></ej:Column>
         <ej:Column Field="ShipCountry" HeaderText="ShipCountry" Width="90" EditType="DropdownEdit" />
     </Columns>
     <EditSettings AllowEditing="True" AllowAdding="True" AllowDeleting="True" EditMode="InlineForm"></EditSettings>
     <ToolbarSettings ShowToolbar="True" ToolbarItems="add,edit,delete,update,cancel"></ToolbarSettings>
 </ej:Grid>

 

C#

 

namespace Sample
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List<EmployeeSpecialists> empl = new List<EmployeeSpecialists>();
            empl.Add(new EmployeeSpecialists { text = "ActionScript", value = "ActionScript" });
            empl.Add(new EmployeeSpecialists { text = "Basic", value = "Basic" });
            empl.Add(new EmployeeSpecialists { text = "C++", value = "C++" });
            empl.Add(new EmployeeSpecialists { text = "C#", value = "C#" });
            this.Grid1.Columns[4].DataSource = empl;
            this.Grid1.DataSource = new MyDataDataContext().Orders.ToList();
            this.Grid1.DataBind();
        }
    }
}

 

The result will be as follows.

 

Fetch data from Code behind for dropdown edit field

Figure 1: Fetch data from Code behind for dropdown edit field


Note

A new version of Essential Studio for ASP.NET is available. Versions prior to the release of Essential Studio 2014, Volume 2 will now be referred to as a classic versions.The new ASP.NET suite is powered by Essential Studio for JavaScript providing client-side rendering of HTML 5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.

The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential Studio for ASP.NET. Although Syncfusion will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below.

You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied