添加一条记录以将结果返回到内存中 [英] add a record to return result in memory

查看:43
本文介绍了添加一条记录以将结果返回到内存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个不同的下拉列表,每个下拉列表都从数据库表中获取数据.

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

表格

  1. TableSchool
  2. TableSubject
  3. TableClass

由于使用LINQ To SQL获取装入数据.我想将下拉列表的第一行添加到-选择学校-选择主题-选择班级

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--

那怎么办?

代码-

 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();

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

我要在此列表或下拉列表的顶部添加一条记录SchoolName =-Select-" SchoolId = 0

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);

tableSchoolItems 是您从数据库中读取的内容

Where tableSchoolItems is what you read from the database

**编辑**

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
            });

这篇关于添加一条记录以将结果返回到内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆