[英]How to divide gridview in two equal parts
I have a GridView 我有一个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>
output after binding code 绑定代码后输出
DREAMTEAM
-----------------
40 pavan11
30 raga11
19 Sidd11
11 Ramesh11
0 Murali11
0 madhu11
0 Sandeep11
0 Gani11
0 prachi
0 Ani11
I need it in following format: 我需要以下格式:
1 pavan11 40 6 Sandeep11 0
2 raga11 30 7 Gani11 0
1-5 here 6-10 here
I am having hard time put counter in front names eg: 1 Pavan11 40 我很难在前面的名称中加上例如:1 Pavan11 40
I sugest to use repeater. 我建议使用中继器。 i did the code bellow
我做了下面的代码
<!-- 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; }
}
I can't post the output image as i run on my local machine for not having reputation... Anyway, hope it helps!!! 我在本地计算机上运行时由于没有声望而无法发布输出图像...无论如何,希望对您有所帮助!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.