如何用Gridview实现以下的页面效果?

山林大 2009-08-16 11:55:28
我想做一个关于项目成员得分的页面,要实现以下的效果:

序号 姓名 总得分

- 1 张三 180
得分一: 分 得分时间:
得分二: 分 得分时间:
得分三: 分 得分时间:
… … … …
+ 2 李四 160
+ 3 王五 150
… … … …

具体说明:我的数据库里有一张项目成员得分表,包含字段:ID、项目ID、姓名(本来是人员ID的,这里就直接用姓名来简便些)、得分、得分时间,其中ID为主键。一个项目中的每个成员可以多次得分,我要的效果是列出每个成员的总得分,如果得分表里没有记录则什么都不显示,有的话就出现上面那种效果,点击“+”后展开能看到该成员每次的得分情况(加起来就是总得分),点击“-”后折叠起来,有下划线的是从数据库读取的。
各路大虾快点来帮看看啊,感激不尽,不用Gridview也行,只要能实现我要的效果,都给分!!!
...全文
508 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
shicsheng 2011-01-22
  • 打赏
  • 举报
回复
winform实现有没有?
legu1 2010-02-25
  • 打赏
  • 举报
回复
很不错,标记一下,收藏了
山林大 2009-08-19
  • 打赏
  • 举报
回复
谢谢楼上的,学习了
山林大 2009-08-17
  • 打赏
  • 举报
回复
能不能给出代码啊,你这么说很抽象啊……囧
怫悰 2009-08-17
  • 打赏
  • 举报
回复
冒泡

用repeater最方便
zl194 2009-08-17
  • 打赏
  • 举报
回复
你只要在DataSet中插入的是主子关系的两个表,自然就是这个样子的.
阿非 2009-08-17
  • 打赏
  • 举报
回复

protected DataView GetScoreDataSource(string Name)
{
int PID = 1;
using (SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=root;database=Test"))
{
SqlDataAdapter sda = new SqlDataAdapter("select [Score],[ScoreTime] from [projectScoreInfo] where [Name]=@Name and [PID]=@PID ", con);
sda.SelectCommand.Parameters.Add(new SqlParameter("@Name", Name));
sda.SelectCommand.Parameters.Add(new SqlParameter("@PID", PID));
DataSet ds = new DataSet();
sda.Fill(ds, "ScoreInfo");
if (ds.Tables.Contains("ScoreInfo"))
{
return ds.Tables["ScoreInfo"].DefaultView;
}
return null;
}//end using block
}



protected void Page_Load(object sender, EventArgs e)
{
int PID = 1;
using (SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=root;database=Test"))
{
SqlDataAdapter sda = new SqlDataAdapter("select [PID],[Name],SUM([Score]) [SumScore] from [projectScoreInfo] where [PID]=@PID group by [Name],[PID] order by [SumScore] desc", con);
sda.SelectCommand.Parameters.Add(new SqlParameter("@PID", PID));
DataSet ds = new DataSet();
sda.Fill(ds, "NameGroupInfo");
if (ds.Tables.Contains("NameGroupInfo"))
{
rpName.DataSource = ds.Tables["NameGroupInfo"].DefaultView;
rpName.DataBind();
}
}//end using block
}
阿非 2009-08-17
  • 打赏
  • 举报
回复

create table projectScoreInfo
(
[ID] int identity(1,1) primary key,
[PID] int ,
[Name] varchar(20),
[Score] int ,
[ScoreTime] datetime
)

insert into projectScoreInfo ([PID],[Name],[Score],[ScoreTime]) select 1,'张三',60,'2009-08-14'
union all select 1,'张三',70,'2009-08-15'
union all select 2,'张三',75,'2009-08-16'
union all select 3,'张三',72,'2009-08-15'
union all select 1,'张三',80,'2009-08-17'
union all select 1,'李四',80,'2009-08-15'
union all select 1,'李四',85,'2009-08-17'
union all select 2,'李四',75,'2009-08-14'
union all select 3,'李四',90,'2009-08-16'
union all select 1,'王二',77,'2009-08-15'
union all select 1,'王二',79,'2009-08-16'
union all select 1,'王二',69,'2009-08-17'
union all select 2,'王二',80,'2009-08-15'
union all select 3,'王二',82,'2009-08-17'

select * from [projectScoreInfo]


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<style type="text/css">

   a { text-decoration: none;color: blue}
  
  

</style>

<script>
function show(obj,id)
{
var el=document.getElementById(id);
if(obj.value=='1')
{
obj.innerText='一';
obj.value='0';
el.style.display='';
}
else
{
obj.innerText='+';
obj.value='1';
el.style.display='none';
}

}
</script>

</head>
<body>
<form id="form1" runat="server">
<asp:Repeater ID="rpName" runat="server">
<HeaderTemplate>
<table>
<thead>
<tr>
<td>
</td>
<td width="30%" align="center">
序号</td>
<td width="30%" align="center">
姓名</td>
<td align="center">
总得分</td>
</tr>
</thead>
</HeaderTemplate>
<AlternatingItemTemplate>
<tbody>
<tr>
<td>
<a href="###" onclick=<%# "show(this,"+"'tb"+ (Container.ItemIndex+1)+"')"%> value="1">
+</a></td>
<td width="30%" align="center">
<%#Container.ItemIndex+1 %>
</td>
<td width="30%" align="center">
<%#Eval("Name") %>
</td>
<td align="center">
<%#Eval("SumScore") %>
</td>
</tr>
</tbody>
<tbody id='<%#"tb"+ (Container.ItemIndex+1) %>' style="display: none">
<asp:Repeater ID="rpScore" DataSource='<%# GetScoreDataSource(Eval("Name").ToString()) %>'
runat="server">
<AlternatingItemTemplate>
<tr>
<td>
</td>
<td width="30%" align="center">
</td>
<td width="30%" align="center">
<%#Eval("Score") %>
</td>
<td align="center">
<%#((DateTime)Eval("ScoreTime")).ToString("yyyy:MM:dd")%>
</td>
</tr>
</AlternatingItemTemplate>
<ItemTemplate>
<tr>
<td>
</td>
<td width="30%" align="center">
</td>
<td width="30%" align="center">
<%#Eval("Score") %>
</td>
<td align="center">
<%#((DateTime)Eval("ScoreTime")).ToString("yyyy:MM:dd")%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</AlternatingItemTemplate>
<ItemTemplate>
<tbody>
<tr>
<td>
<a href="###" onclick=<%# "show(this,"+"'tb"+ (Container.ItemIndex+1)+"')"%> value="1">
+</a></td>
<td width="30%" align="center">
<%#Container.ItemIndex+1 %>
</td>
<td width="30%" align="center">
<%#Eval("Name") %>
</td>
<td align="center">
<%#Eval("SumScore") %>
</td>
</tr>
</tbody>
<tbody id='<%#"tb"+ (Container.ItemIndex+1) %>' style="display: none">
<asp:Repeater ID="rpScore" DataSource='<%# GetScoreDataSource(Eval("Name").ToString()) %>'
runat="server">
<AlternatingItemTemplate>
<tr>
<td>
</td>
<td width="30%" align="center">
</td>
<td width="30%" align="center">
<%#Eval("Score") %>
</td>
<td align="center">
<%#((DateTime)Eval("ScoreTime")).ToString("yyyy:MM:dd")%>
</td>
</tr>
</AlternatingItemTemplate>
<ItemTemplate>
<tr>
<td>
</td>
<td width="30%" align="center">
</td>
<td width="30%" align="center">
<%#Eval("Score") %>
</td>
<td align="center">
<%#((DateTime)Eval("ScoreTime")).ToString("yyyy:MM:dd")%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>

wangbin1986 2009-08-17
  • 打赏
  • 举报
回复
datalist or repeater 在控件内加入lable,使用<%# Eval("Item") %>绑定数据信息
wangyinnet 2009-08-17
  • 打赏
  • 举报
回复
repeter里嵌套个repeter,
父级repeter绑定一张表,子repeter根据父级repeter里ID,绑定下就行了,很简单的.
love_cloud 2009-08-17
  • 打赏
  • 举报
回复
不会 帮顶 主要是没看懂什么意思 用datalist行不行?
阿非 2009-08-17
  • 打赏
  • 举报
回复
你目前是一个项目下,如果表中有多个项目,是否项目也要遍历呢?
山林大 2009-08-17
  • 打赏
  • 举报
回复
3楼,这不是主子表,就一个表
5楼,这方法我想到过,不行滴,只会把某列拉得很长
爱此清夜雨 2009-08-17
  • 打赏
  • 举报
回复
我想在gridview增加列,然后编辑模版,再拖入个gridview,在数据库建立相应关系。应该可以吧!
bychgh 2009-08-17
  • 打赏
  • 举报
回复
帮顶

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧