add a record to return result in memory
I have some 3 different dropdown list and each dropdown fetch data from database table.
Tables
- TableSchool
- TableSubject
- TableCla开发者_如何学编程ss
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
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
});
精彩评论