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

In a DropDownEdit column, how to display text instead of value

Hi,

I'm new to Syncfusion, and in the process of trying out a few different things to try to figure out how everything works. I'm using ASP.NET Web Forms, and I have a question about how to display text instead of value in a dropdownedit column.

I used the example from this link to populate the dropdown values, and it does work fine when I try to add a new row. It shows the text instead of the value in the dropdown from the datasource I provided. But as far as the grid itself is concerned, it only shows the values, and not the text itself.

This is my grid:

<ej:Grid ID="buildingsGrid" runat='server' AllowPaging="true" AllowSorting="true" AllowFiltering="true" OnServerAddRow="buildingsGrid_ServerAddRow" OnServerDeleteRow="buildingsGrid_ServerDeleteRow">
    <Columns>
        <ej:Column Field="UserBuildingID" IsPrimaryKey="true" Visible="false"></ej:Column>
        <ej:Column Field="buildingid" HeaderText="Building" EditType="DropdownEdit"></ej:Column>
    </Columns>
    <EditSettings AllowAdding="true" AllowEditing="false" AllowDeleting="true" />
    <ToolbarSettings ShowToolbar="true" ToolbarItems="add,delete,update,cancel"></ToolbarSettings>
</ej:Grid>

I databind it at PageLoad, and databind the dropdown as well. The datatable that's used as the datasource for the grid returns three columns: UserBuildingID, buildingid and Name. Here the buildingid and Name are connected, and I want to display the Name instead of buildingid, but the value should still be buildingid.

For databinding the dropdown column, this is what I use:

List<object> dropObj = new List<object>(); 
//read data from the SQL table 
using (SqlDataReader dr = cmd.ExecuteReader()) 
    while (dr.Read()) 
    
         //Convert Table rows to text/value pair 
         dropObj.Add(new { text = dr.GetValue(0).ToString(), value = dr.GetValue(0) }); 
    
this.buildingsGrid.Columns[1].DataSource = dropObj;

How do I make sure that the text is displayed instead of the value in such a scenario?

Thanks,
Rajkishan


5 Replies

RR Rajkishan Rajappan March 5, 2020 04:35 PM UTC

To add to this, I've tried setting the ForeignKeyField as buildingid and ForeignKeyValue as Name for the dropdownedit column, but doing that just makes the columns blank and not display anything at all.


RR Rajkishan Rajappan March 6, 2020 02:58 AM UTC

Never mind! I figured it out. I just had to specify the ForeignKeyValue and ForeignKeyField as "text" and "value" respectively. Now it displays correctly!


MP Manivannan Padmanaban Syncfusion Team March 6, 2020 10:59 AM UTC

Hi Rajkishan, 

We are pleased to hear that the reported issue has been resolved. 

If you need further assistance please get back to us. We will be happy to assist you. 

Regards, 
Manivannan Padmanaban. 



JS Jan Streblow May 11, 2021 09:47 AM UTC

Hi,

I have a similar issue and tried to adopt the solution in this post, but for me it does not work. Got this grid in aspx:



with this SQL data source:



and this c# code:

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List aobj = new List();
                aobj.Add(new { text = "1234567 Finanzstelle A", value = "1234567" });
                aobj.Add(new { text = "1237654 Finanzstelle B", value = "1237654" });
                aobj.Add(new { text = "1238888 Finanzstelle C", value = "1238888" });
                aobj.Add(new { text = "1239000 Finanzstelle D", value = "1239000" });
                this.Grid1.Columns[0].DataSource = aobj;
                this.Grid1.DataBind();
            }
        }

The list shows text from drop down data source instead of value / ID correctly. But when I edit it displays "Details of undefined" with wierd fields and values or in case of EditMode="Normal" an empty field, though the dropdown list displays and works correctly:

  
 

For me everything looks good, so any suggestions?

Best regards
Jan


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team May 12, 2021 01:36 PM UTC

Hi Jan, 

Thanks for using Syncfusion products. 

Query#:- But when I edit it displays "Details of undefined" with wierd fields and values or in case of EditMode="Normal" an empty field, though the dropdown list displays and works correctly: 

From analyzing your code example, you have not enabled IsPrimaryKey property in anyone of the columns which is necessary to perform Editing operations in Grid. Also IsPrimaryKey field must contains unique values. So we suggest to enable IsPrimaryKey property  

Refer to the code below:- 
<ej:Grid ID="FlatGrid" runat="server" IsResponsive="true” AllowPaging="True"> 
           .    .   . 
               
          <Columns> 
                <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="True" TextAlign="Right" Width="75" /> 
                  .    . 
            </Columns> 
            
</ej:Grid>   


Refer to the KB link:- 

Also in your screenshot you have shown like “Details of undefined” in Dialog. But you have used “Normal” mode in code example. So share us the clear Explanation about the Issue you have faced about details of undefined. 

Regards, 
Farveen sulthana T 


Loader.
Live Chat Icon For mobile
Up arrow icon