110,571
社区成员
发帖
与我相关
我的任务
分享
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
}
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>