asp:GridView 合并相同資料項目行

來源:互聯網
上載者:User

前台:

<asp:GridView ID="gvInfo" runat="server" AutoGenerateColumns="False" CellPadding="4"                    ForeColor="#333333" HorizontalAlign="left" EmptyDataText="無" OnDataBound="GridView1_DataBound" Width="100%">                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />                    <Columns>                        <asp:TemplateField HeaderText="序號">                            <ItemTemplate>                                <%#Container.DataItemIndex+1%>                            </ItemTemplate>                            <ItemStyle Width="5%" HorizontalAlign="Center" />                        </asp:TemplateField><asp:BoundField DataField="ShowDay" HeaderText="日期">                            <ItemStyle Width="10%" />                        </asp:BoundField>                        <asp:BoundField DataField="ShowTime" HeaderText="時間">                            <ItemStyle Width="20%" />                        </asp:BoundField>                        <asp:BoundField DataField="Place" HeaderText="地點">                            <ItemStyle Width="15%" />                        </asp:BoundField>                        <asp:BoundField DataField="Content" HeaderText="內容">                            <ItemStyle Width="25%" />                        </asp:BoundField>                        <asp:BoundField DataField="Persons" HeaderText="參加人員">                            <ItemStyle Width="15%" />                        </asp:BoundField>                    </Columns>                    <EditRowStyle BackColor="#2461BF" />                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />                    <HeaderStyle BackColor="#cadef4" Font-Bold="True" ForeColor="#3b6798" />                    <AlternatingRowStyle BackColor="White" />                </asp:GridView

後台:

protected void Page_Load(object sender, EventArgs e){gvInfo.DataSource = List<T>;gvInfo.DataBind();}protected void GridView1_DataBound(object sender, EventArgs e){int row = 0;for (int i = 1; i < gvInfo.Rows.Count; i++){if (gvInfo.Rows[i].Cells[1].Text == gvInfo.Rows[i - 1].Cells[1].Text){if (gvInfo.Rows[row].Cells[1].RowSpan == 0) gvInfo.Rows[row].Cells[1].RowSpan++;gvInfo.Rows[row].Cells[1].RowSpan++;gvInfo.Rows[i].Cells[1].Visible = false;}else{row = i;}}} 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.