Dictionary应用
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应用的更多相关文章
- C#数组,List,Dictionary的相互转换
本篇文章会向大家实例讲述以下内容: 将数组转换为List 将List转换为数组 将数组转换为Dictionary 将Dictionary 转换为数组 将List转换为Dictionary 将Dicti ...
- ASP.NET Aries JSAPI 文档说明:AR.DataGrid、AR.Dictionary
AR.Global 文档 1:对象或属性: 名称 类型 说明 DG 对象 DataGrid操作对象 //datagrid集合,根据ID取出DataGrid对象,将Json当数组用. Items: ne ...
- WebAPI接口返回ArrayList包含Dictionary对象正确解析
一.问题提出 为了减少流量,将key-value(键值对)直接输出到Dictionary<string, string>,接口返回结果如下: 其中{}里面内容如下: 上图显示600是键,4 ...
- Linq在Array,List,Dictionary中的应用
Linq在Array,List,Dictionary中的应用 今天在实际工作中需要对array,list,dictionary进行排序,试一试linq,发现非常好用,代码如下: using Syste ...
- python之最强王者(8)——字典(dictionary)
1.Python 字典(Dictionary) 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包 ...
- Swift3 - String 字符串、Array 数组、Dictionary 字典的使用
Swift相关知识,本随笔为 字符串.数组.字典的简单使用,有理解.使用错误的地方望能指正. ///************************************************** ...
- [LeetCode] Alien Dictionary 另类字典
There is a new alien language which uses the latin alphabet. However, the order among letters are un ...
- Dictionary
命名空间:System.Collections.Generic(程序集:mscorlib) Dictionary<TKey, TValue> 类 一般用法:通过key获取value,k ...
- 关于 Dictionary<string,string>,和List<T>在View的使用
在MVC中Dictionary<string,string>如何应用到View页面中呢,例: <input type="text" name=key value= ...
- Dictionary Learning(字典学习、稀疏表示以及其他)
第一部分 字典学习以及稀疏表示的概要 字典学习(Dictionary Learning)和稀疏表示(Sparse Representation)在学术界的正式称谓应该是稀疏字典学习(Sparse Di ...
随机推荐
- 阅读Linux内核源码时建立tags索引
比如在阅读arm架构的Linux内核代码时想建立arm架构相关的索引,可以使用下面的命令: make ARCH=arm tags
- 基于设备树的TQ2440触摸屏驱动移植
平台 开发板:tq2440 内核:Linux-4.9 u-boot:u-boot-2015.04 概述 之前移植了LCD驱动,下面继续移植触摸屏驱动,然后将tslib也移植上去. 正文 一.移植触 ...
- Javascript中的依赖注入
首先通过带参函数来定义一个Javascript函数,相当于C#中的一个类. var Person = function(firstname, lastname){ this.firstname = f ...
- Spring Cloud Gateway服务网关
原文:https://www.cnblogs.com/ityouknow/p/10141740.html Spring 官方最终还是按捺不住推出了自己的网关组件:Spring Cloud Gatewa ...
- libxml/HTMLparser.h file
在导入asihttprequest包时出问题导入了libxml2.dylib,但是却提示libxml/HTMLparser.h file not found,那是因为你的开发环境默认的路径无法找到这个 ...
- springboot redis多数据源设置
遇到这样一个需求:运营人员在发布内容的时候可以选择性的发布到测试库.开发库和线上库. 项目使用的是spring boot集成redis,实现如下: 1. 引入依赖 <dependency> ...
- libgdx 环境搭建
1:环境搭建: (1)首先进入官网,http://libgdx.badlogicgames.com/download.html 点击下方的Releases.进行下载最新的版本号就可以. 这个为我们开 ...
- IIS回收后首次访问慢问题
禁用时间间隔回收 设置为0 然后设置指定时间回收 0:00:00 然后设置脚本 @echo off @echo 正在关掉所有的IE进程(需要设置默认浏览器是IE) taskkill /im iexpl ...
- Android中的输入法
提起输入法我就想到了Edittext,输入法可以自动根据inputType来改变键盘的布局,在支付钱包中还特别隐藏的系统自带的输入法,直接让用户用软件自己的输入法,提高了安全性.所以,我们应该对输入法 ...
- [Android Pro] 由模块化到组件化(一)
cp from : https://blog.csdn.net/dd864140130/article/details/53645290 在Android SDK一文中,我们谈到模块化和组件化,现在我 ...