当ASP.NET GridView索引发生更改时,方法无法正常工作

时间:2015-08-06 12:03:18

标签: c# asp.net gridview

我有一个方法,在加载页面和更改gridview的页面时执行。此方法导入数据,以及设置rowspans。 数据导入正在每个站点上工作,但Rowspan只在第一页上设置。
这是我的C#代码:

 protected void grdvProductChurn_DataBound()
{
    for (int rowIndex = grdvProductChurn.Rows.Count - 2; rowIndex >= 0; rowIndex += -1)
    {
        GridViewRow gvRow = grdvProductChurn.Rows[rowIndex];
        GridViewRow gvPreviousRow = grdvProductChurn.Rows[rowIndex + 1];
        for (int cellCount = 0; cellCount <= gvRow.Cells.Count - 8; cellCount++)
        {
            if (gvRow.Cells[cellCount].Text == gvPreviousRow.Cells[cellCount].Text)
            {
                if (gvPreviousRow.Cells[cellCount].RowSpan < 2)
                {
                    gvRow.Cells[cellCount].RowSpan = 2;
                }
                else
                {
                    gvRow.Cells[cellCount].RowSpan = gvPreviousRow.Cells[cellCount].RowSpan + 1;
                }
                gvPreviousRow.Cells[cellCount].Visible = false;
            }
        }
    }

    if (grdvProductChurn != null)
    {
        GridViewRow row = new GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal);
        TableHeaderCell left = new TableHeaderCell();
        left.Text = "";
        left.ColumnSpan = 2;
        row.Cells.Add(left);



        TableCell totals = new TableHeaderCell();
        totals.ColumnSpan = grdvProductChurn.Columns.Count - 2;
        totals.Text = "Anzahl";
        row.Cells.Add(totals);


    }

}

这是我的asp GridView:

    <asp:GridView ID="grdvProductChurn" runat="server" CellPadding="4" HeaderStyle-BorderStyle="None" autopostback="true"
    BorderColor="#666666" BorderStyle="Solid" AllowPaging="True" AutoGenerateColumns="false" PageSize="30" DataSourceID="DataSource_ProductChurn" 
    AllowSorting="True" ForeColor="#666666" CellSpacing="1" DataFormatString="{0:###,###,###,###,###}" 
    CaptionAlign="Left"  Width="960px" HeaderStyle-HorizontalAlign="Center" HorizontalAlign="Center" CssClass="GridView2"
    Height="119px" OnRowCreated="grdvProductChurn_RowCreated" onpageindexchanged="grdvProductChurn_PageIndexChanged" > 

然后我也有onpageindexchanged的方法。它在我更改页面时执行,但是rowspan不起作用。

   public void grdvProductChurn_PageIndexChanged(object sender, EventArgs e)
    {
        grdvProductChurn_DataBound();

    }

0 个答案:

没有答案