SQL语句那么写是正确的。如果那么做看不懂,可以先把所有数据取到DataTable里,然后在C#里通过循环构造你要的表。至于显示时用TextBox,可以在GridView中用TemplateItem阿。
解决方案 »
- jQuery自定义插件返回值与方法问题
- 伤脑经的树形结构菜单
- dimensions 为何不在本机上就不好用
- 用javascript控制Radio的隐藏和显示
- 如何叠加图片到不同的热区?
- 用dom编程动态生成html,但onclick不反应,请帮忙?
- 还是刚才那个问题的延续··我想向弹出div里的表格写值应该怎么做呀···往每一个td里写一个数据库读取··在送100分~!!
- alert弹出的消息框为何会出现这样的怪问题?
- 动态改变div 的z-index属性的问题,[请帮忙改一下程序,谢谢!]
- 有谁知道rtsp://www。。。。。怎么下载嘛?
- js 正则匹配问题
- js如何输出16进制的代码成为图片并显示
create table #tbl_0
(
color nvarchar(12),
nsize nchar(1),
store int
)
insert into #tbl_0
select 'red', 'S', '10' union all
select 'red', 'M', '80' union all
select 'white', 'L', '50' union all
select 'white', 'S', '60' select * from #tbl_0
--结果
--red S 10
--red M 80
--white L 50
--white S 60
declare @sql varchar(4000)
set @sql = ' select color,'
select @sql= @sql+'isnull(sum(case nsize when '''+ns+''' then isnull(store,0) end),0) '''+ns+''','
from (select 'S' as ns union all select 'M' union all select 'L') a
set @sql = stuff(@sql,len(@sql),1,'')
set @sql=@sql+ ' from #tbl_0 group by color'exec(@sql)--结果
--red 10 80 0
--white 60 0 50drop table #tbl_0
select color,
isnull(sum(case nsize when 'S' then isnull(store,0) end),0) 'S',
isnull(sum(case nsize when 'M' then isnull(store,0) end),0) 'M',
isnull(sum(case nsize when 'L' then isnull(store,0) end),0) 'L'
from #tbl_0 group by color
4楼CutBug的方法可行,先谢了,我还有些问题要请教,如果不够分我再加。
问题1:显示结果如下:
颜色 S M L
红色 10 80 0
白色 60 0 50 但是,我绑定GridView的时候,在编辑列里我是设定了"自动生成字段"打勾,如果我是设定了某个特定的字段要怎么设定? 我搞了很久不明白,BoundField的DataField应该绑定什么?或者是用TemplateField的时候添加TextBox的时候TextBox绑定什么? Eval("里面写什么?")问题2 :假如上面的问题搞定了,如果我要加一个Button控件,怎么将TextBox控件里的数据修改后点击Button控件就保存到数据库里? 请高手们指教,谢谢!