惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
L
LangChain Blog
云风的 BLOG
云风的 BLOG
Jina AI
Jina AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
InfoQ
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
小众软件
小众软件
量子位
The GitHub Blog
The GitHub Blog
博客园 - 【当耐特】

博客园 - Freeman Shen

.NET面试题 (转)C#中的Abstract和Virtual函数区分,因我老弄不明白这个问题,所以转到这儿 Check Constraints限制本表的行数 数据库中主键和外键的设计原则 讲解SQL Injection一篇不错的文章,地址贴一下 Queue<(Of <(T>)>) 类,msdn上的一篇文章,便于查看 初次接触.Net下的信号量(semaphore) 某“高人”谈论股市,对现在行情的分析 编辑电影字幕,编辑srt格式 左联,右联和内联的区别(图示) 用JavaScript如何获取客户端的操作系统是window2000还是window xp? 在IBatisNet框架,MasterPage,基类中配置Ajaxpro 自从离开哈尔滨后就没再管理这个blog了,以后还得继续努力啊 70-528试题2:仍然是有关xml的 题1的答案是(B),这是一个xml和schema的问题! 70-582试题1 由清明节想到的 今天心情不太好,没什么可写的 生命之价
由DataBind()而发现的
Freeman Shen · 2007-03-29 · via 博客园 - Freeman Shen

昨天和今天遇到了同一个问题,一个页面有两个或多个GridView,DropDownList,DataList,DataGrid,ListBox这中控件,在同时绑定数据时结果只有最后一个绑定成功!

 1    protected void Page_Load(object sender, EventArgs e)
 2    {
 3        if (!IsPostBack)
 4        {
 5            GetAllDepartment();
 6            GetAllOS();
 7        }

 8    }

 9
10    public void GetAllDepartment()
11    {
12        dt = business.GetAllDepartment();
13        this.departmentListSelect.DataSource = dt;
14        this.departmentListSelect.DataValueField = dt.Columns[0].ColumnName;
15        this.departmentListSelect.DataTextField = dt.Columns[1].ColumnName;
16        this.departmentListSelect.Items.Insert(0new ListItem("请选择""0"));
17    }

18
19    public void GetAllOS()
20    {
21        dt = business.GetAllOS();
22        this.oSListSelect.DataSource = dt;
23        this.oSListSelect.DataValueField = dt.Columns[0].ColumnName;
24        this.oSListSelect.DataTextField = dt.Columns[1].ColumnName;
25        this.oSListSelect.Items.Insert(0new ListItem("请选择""0"));
26    }

结果最后才找到错误的原因所在.
在定义数据源后必须要"将数据源绑定到被调用的服务器控件及其所有子控件",所以少了一个DataBind()的过程.
在16行和25行后加入DataBind()即可解决。
有关DataBind()的参见:
http://msdn2.microsoft.com/zh-cn/library/system.web.ui.control.databind(VS.80).aspx

posted on 2007-03-29 13:22  Freeman Shen  阅读(431)  评论()    收藏  举报