2014-03-12 78 views
0

劃分的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> 

輸出綁定代碼

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

回答

1

我sugest使用中繼器。我做了下面的代碼

<!-- 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; } 
    } 

我無法發佈輸出圖像,因爲我在我的本地機器上運行沒有聲望......無論如何,希望它有幫助!

相關問題