add a record to return result in memory

2019-09-09 22:57发布

I have some 3 different dropdown list and each dropdown fetch data from database table.

Tables

  1. TableSchool
  2. TableSubject
  3. TableClass

As the for load data is fetch using LINQ To SQL. I want to add first row of dropdown to --Select School-- --Select Subject-- --Select Class--

How can that be done?

Code -

 var list = (from i in context.MAT_TableSchool
                    select
                        new
                        {
                            SchoolName= string.Format("SN - {0}", i.SchoolName),
                            SchoolId = i.SchoolId
                        });

this._schoolDropdown.DataSource = list; this._schoolDropdown.DataBind();

What I want is to add a record SchoolName="-Select-" SchoolId=0 at top of this list or dropdown

1条回答
做个烂人
2楼-- · 2019-09-09 23:45

You don't show a lot of code, so I can only be very generic:

var schoolItems = new string[]{ "--Select School--" }
     .Concat(tableSchoolItems);

Where tableSchoolItems is what you read from the database

** Edit **

var list = new [] { new
            {
                SchoolName = "--Select--",
                SchoolId = 0
            } }.Concat(
    from i in context.MAT_TableSchool 
    select new
            {
                SchoolName= string.Format("SN - {0}", i.SchoolName),
                SchoolId = i.SchoolId
            });
查看更多
登录 后发表回答