using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace ProjectWeb
{
public partial class DataSetTable : System.Web.UI.Page
{
//创建字典,好处就是使用ContainsKey功能
private Dictionary<string, string> dicObject = new Dictionary<string, string>(); protected void Page_Load(object sender, EventArgs e)
{
//把DataTable数据添加到Dictionary字典
DataTable dt_sn = GetData().Tables[0];
this.dicObject.Clear();
foreach (DataRow dr in dt_sn.Rows)
this.dicObject.Add(dr["id"].ToString(), dr["name"].ToString()); //Dictionary字典的数据添加到页面DropDownList1
this.DropDownList1.Items.Clear();
this.DropDownList1.Items.Add(new ListItem("第一张表"," "));
foreach (KeyValuePair<string, string> kv in dicObject)
this.DropDownList1.Items.Add(new ListItem(kv.Value, kv.Key)); //第二张表数据
DataTable dt_te = GetData().Tables[1];
this.DropDownList2.Items.Clear();
this.DropDownList2.Items.Add(new ListItem("第二张表", " "));
foreach (DataRow dr in dt_te.Rows)
this.DropDownList2.Items.Add(new ListItem(dr["name"].ToString(), dr["id"].ToString()));
}
#region 返回数据集
private DataSet GetData()
{
//创建第一张表
DataTable dt_sn = new DataTable();
//添加列
dt_sn.Columns.Add("id");
dt_sn.Columns.Add("name");
//添加行
DataRow dr_sn = dt_sn.NewRow();
dr_sn["id"] = "1";
dr_sn["name"] = "杨秀徐";
dt_sn.Rows.Add(dr_sn);
//表名称
dt_sn.TableName = "SN"; //创建第二张表
DataTable dt_te = new DataTable();
//添加列
dt_te.Columns.Add("id");
dt_te.Columns.Add("name");
//添加行
DataRow dr_te = dt_te.NewRow();
dr_te["id"] = "2";
dr_te["name"] = "杨四节";
dt_te.Rows.Add(dr_te);
//表名称
dt_te.TableName = "Te"; DataSet ds = new DataSet();
//把表DataTable添加到数据集DataSet
ds.Tables.Add(dt_sn);
ds.Tables.Add(dt_te); return ds;
}
#endregion
}
}

Dictionary应用的更多相关文章

  1. C#数组,List,Dictionary的相互转换

    本篇文章会向大家实例讲述以下内容: 将数组转换为List 将List转换为数组 将数组转换为Dictionary 将Dictionary 转换为数组 将List转换为Dictionary 将Dicti ...

  2. ASP.NET Aries JSAPI 文档说明:AR.DataGrid、AR.Dictionary

    AR.Global 文档 1:对象或属性: 名称 类型 说明 DG 对象 DataGrid操作对象 //datagrid集合,根据ID取出DataGrid对象,将Json当数组用. Items: ne ...

  3. WebAPI接口返回ArrayList包含Dictionary对象正确解析

    一.问题提出 为了减少流量,将key-value(键值对)直接输出到Dictionary<string, string>,接口返回结果如下: 其中{}里面内容如下: 上图显示600是键,4 ...

  4. Linq在Array,List,Dictionary中的应用

    Linq在Array,List,Dictionary中的应用 今天在实际工作中需要对array,list,dictionary进行排序,试一试linq,发现非常好用,代码如下: using Syste ...

  5. python之最强王者(8)——字典(dictionary)

    1.Python 字典(Dictionary) 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包 ...

  6. Swift3 - String 字符串、Array 数组、Dictionary 字典的使用

    Swift相关知识,本随笔为 字符串.数组.字典的简单使用,有理解.使用错误的地方望能指正. ///************************************************** ...

  7. [LeetCode] Alien Dictionary 另类字典

    There is a new alien language which uses the latin alphabet. However, the order among letters are un ...

  8. Dictionary

    命名空间:System.Collections.Generic(程序集:mscorlib) Dictionary<TKey, TValue> 类   一般用法:通过key获取value,k ...

  9. 关于 Dictionary<string,string>,和List<T>在View的使用

    在MVC中Dictionary<string,string>如何应用到View页面中呢,例: <input type="text" name=key value= ...

  10. Dictionary Learning(字典学习、稀疏表示以及其他)

    第一部分 字典学习以及稀疏表示的概要 字典学习(Dictionary Learning)和稀疏表示(Sparse Representation)在学术界的正式称谓应该是稀疏字典学习(Sparse Di ...

随机推荐

  1. 集群服务器下使用SpringBoot @Scheduled注解定时任务

    原文:https://blog.csdn.net/huyang1990/article/details/78551578 SpringBoot提供了 Schedule模块完美支持定时任务的执行 在实际 ...

  2. Android控件之ImageSwticher

    Android控件之ImageSwticher 1. ImageSwticher介绍 ImageSwitcher是图片切换的控件,它能实现图片切换时的动画效果,包括图片导入效果.图片消失效果等等.An ...

  3. Objective-C内存布局

    在我的理解来说: 对象(object)即一块内存,本文要探讨的是一个Objective-C对象在内存的布局(layout)问题,水果的官方文档有说,一个类(class)如果不需要从NSObject继承 ...

  4. dll 显示调用

    今天尝试写了一个简单的C++DLL,并且用另一个CPP调用它,啥都不说,先贴代码 1.DLL(冒泡算法) extern "C" 必须最左 _declspec(dllexport)和 ...

  5. linux下一个网卡配置多个IP

    转自:http://blog.csdn.net/beckdon/article/details/15815197 最常用的给网卡配置ip的命令为 #ifconfig eth0 192.168.0.1 ...

  6. 转: MySQL5.7 ERROR 1142 (42000)问题

    1,mysql全库导入报错 [root@dev_121_21 ~]# mysql--socket=/usr/local/mysql/mysql.sock --default-character-set ...

  7. 如何在SpringMVC中获取request对象

    1.注解法 @Autowired private HttpServletRequest request; <listener> <listener-class> org.spr ...

  8. Java分布式系统高并发解决方案

    对于我们开发的网站,如果网站的访问量非常大的话,那么我们就需要考虑相关的并发访问问题了.而并发问题是绝大部分的程序员头疼的问题, 但话又说回来了,既然逃避不掉,那我们就坦然面对吧~今天就让我们一起来研 ...

  9. Just-In-Time Debugging in Visual Studio 禁止VS在服务器上调试

    To disable Just-In-Time debugging by editing the registry On the Start menu, search for and run rege ...

  10. 奇怪吸引子---AnishchenkoAstakhov

    奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...