Displaying two fields in one select list - C#

Displaying two fields in one select list - C#

nfitenfite Posts: 10Questions: 2Answers: 0

Hi Alan,

I am presented with an issue.

I am trying to find a way to display to the user two separate fields from my database concatenated using datatables and c# server side.

On the Database side i have a table Item - reference Planner(int)

I have a Planner table which has 3 column id, Name, Description

'''in my select list or drop down list i need the viewer to see Name + "-" + Description
SO please see below and let me know if there is a way using options to complete this task,

or any other way you could think of that i can complete displaying two fields in the same select list.

Thanks,
Nick

My model contains

Item which includes Planner

and Planner which includes, id, Name, Description

Below is an excerpt from my controller

public IHttpActionResult ProjectItem(int projectid)
{
var request = HttpContext.Current.Request;
var settings = Properties.Settings.Default;

        using (var db = new Database(settings.DbType, settings.DbConnection))
        {
            var response =
            new Editor(db, "Item", "ItemID")

            .Model<ItemGenModel1>()

                .Field(new Field("Item.Planner")
               .Options("Planner", "id", "Description", q => q.Where("description", "%do not use%", "NOT LIKE"))


        )

Replies

  • allanallan Posts: 64,323Questions: 1Answers: 10,622 Site admin

    Hi Nick,

    You can have the option method read multiple fields for the label and also provide a custom renderer which describes how the label should be created.

    The documentation for that is available here. In particular, have a look at the third example which uses a renderer for multiple fields.

    Allan

  • nfitenfite Posts: 10Questions: 2Answers: 0

    Allan,

    I have the following code

    .Field(new Field("Item.SPRP6")
    .Options(new Options())
    .Table("SRP6")
    .Value("id")
    .Render(row => row["Name"] + "-" + row["Description"])

                    )
    

    in the line .Options(new Options())

    i receive the following error the type or namespace 'Options' could not be found

    so i do not have access i believe to complete this action....

  • allanallan Posts: 64,323Questions: 1Answers: 10,622 Site admin

    Have you installed Editor 1.6? The Options class is new in 1.6.

    Allan

This discussion has been closed.