我有一个GridView
<asp:GridView ID="topDreamTeam" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField HeaderText="DREAMTEAM" DataField="teamName" />
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="topDTID" runat="server" Text='<%#Eval("score") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
绑定代码后的输出
DREAMTEAM
-----------------
40 pavan11
30 raga11
19 Sidd11
11 Ramesh11
0 Murali11
0 madhu11
0 Sandeep11
0 Gani11
0 prachi
0 Ani11
我需要以下格式:
1 pavan11 40 6 Sandeep11 0
2 raga11 30 7 Gani11 0
1-5 here 6-10 here
我很难将名单放在前面的名字中,例如:1 Pavan11 40
答案 0 :(得分:1)
我建议使用中继器。我做了下面的代码
<!-- Place this on the aspx file -->
<div style="width: 217px; float: left;">
<asp:Repeater ID="repeater1" runat="server">
<HeaderTemplate>
<ul style="list-style: none;">
</HeaderTemplate>
<ItemTemplate>
<li>
<%# DataBinder.Eval(Container.DataItem, "cod")%>
-
<%# DataBinder.Eval(Container.DataItem, "teamName") %>
-
<%# DataBinder.Eval(Container.DataItem, "score") %></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
<div style="width: 217px; float: left;">
<asp:Repeater ID="repeater2" runat="server">
<HeaderTemplate>
<ul style="list-style: none;">
</HeaderTemplate>
<ItemTemplate>
<li>
<%# DataBinder.Eval(Container.DataItem, "cod")%>
-
<%# DataBinder.Eval(Container.DataItem, "teamName") %>
-
<%# DataBinder.Eval(Container.DataItem, "score") %></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
//Place this on the code behind
protected void Page_Load(object sender, EventArgs e)
{
List<person> lstPerson = new List<person>();
lstPerson.Add(new person() {cod = lstPerson.Count + 1, teamName = "pavan11", score = "40" });
lstPerson.Add(new person() {cod = lstPerson.Count + 1, teamName = "raga11", score = "30" });
lstPerson.Add(new person() {cod = lstPerson.Count + 1, teamName = "Sidd11", score = "19" });
lstPerson.Add(new person() {cod = lstPerson.Count + 1, teamName = "Ramesh11", score = "11" });
lstPerson.Add(new person() {cod = lstPerson.Count + 1, teamName = "Murali11", score = "0" });
lstPerson.Add(new person() {cod = lstPerson.Count + 1, teamName = "madhu11", score = "0" });
lstPerson.Add(new person() {cod = lstPerson.Count + 1, teamName = "Sandeep11", score = "0" });
lstPerson.Add(new person() {cod = lstPerson.Count + 1, teamName = "Gani11", score = "0" });
lstPerson.Add(new person() {cod = lstPerson.Count + 1, teamName = "prachi", score = "0" });
lstPerson.Add(new person() {cod = lstPerson.Count + 1, teamName = "Ani11", score = "0" });
var part1 = lstPerson.Count / 2;
repeater1.DataSource = lstPerson.Take(part1).ToList<person>();
repeater1.DataBind();
repeater2.DataSource = lstPerson.Skip(part1).ToList<person>();
repeater2.DataBind();
}
//The class created for the repeater binding
public class person
{
public Int32 cod { get; set; }
public String teamName { get; set; }
public String score { get; set; }
}
我无法发布输出图像,因为我在本地计算机上运行没有声誉......无论如何,希望它有所帮助!!!