当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 关于数据绑定在Web页面呈现效果的一点小技巧

ASP.NET
Eric的无限级Tree演示
C#中操作Excel的方法(一)
Data Access Application Block V2 类库中文文档(转贴 )
大文件上传浅谈,以及遇到的问题
做软件的困难:非技术困惑
走进C# (我的C#学习之旅)之二
Northwind中一个特别之处
.net中取当前系统的想关信息的类
写组件时需要的注释与属性书写方法
XPath序列之五
使用CommandBuilder为DataAdaper生成的Command更新数据源时的注意事项!
如何列举出网络上所有的SQL Server服务器
XPath序列之一
如何在C#里面象js一样可以直接计算字符串的值
XPath序列之三
电子秤和PC之间的数据通讯(应答)
从SQL Server中读写大数据列。
通过CDO组件对NNTP服务器发送消息
Singleton深入浅出
悲观观定SQL Server和Oracle

ASP.NET 中的 关于数据绑定在Web页面呈现效果的一点小技巧


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 227 ::
收藏到网摘: n/a

今天在开发当中遇到:一个栏目要求以上图的方式显示,我用了2个DataGrid绑定一个1个栏目,

    “ 医药内幕”这个栏目的数据库编号是:category1=1,category2=2。

左边我用DataGrid1来帮定:呈现的数据是“医药内幕”栏目里TOP前 4 位的记录

   string str1 = "select top 4 title from NewsInfo where category1=1 and category2=2 order   by     id  desc";
   DataGrid1.DataSource = sqlBase.ExecuteDataView(str1);
   DataGrid1.DataBind();


右边边我用DataGrid2来帮定:呈现的数据是“医药内幕”栏目里TOP 前8 位中后 4 位的记录

string str1 = "select top 4 title from NewsInfo where id 
                    not in ( select top 4 id
from NewsInfo where category1=1 and category2=2
                    order by id desc ) and category1=1 and category2=2order by id desc";
   DataGrid1.DataSource = sqlBase.ExecuteDataView(str1);
   DataGrid1.DataBind();

这样邦定,就可以让一个栏目的数据在页面上分2个地方甚至多个地方显示,而且可以不重复的显示最新的记录,关键用到了SQl当中的 not in()。这是我所体会的,希望大家指正。