ASP.net Grid paging with merged rows

家住魔仙堡 提交于 2019-12-22 13:58:15

问题


I am currently using GridView to display tabular data. I need to merge cells in the first column that have equal values. At the moment I have code in the PreRender event to set the RowSpan property for me, and it's working fine.

The problem is I cannot use paging, since the pages will split in the middle of a section where the first field is equal.

I want the record count for paging to count one for each of the merged rows, rather than one for each sub-row.

Is this possible with GridView or some other jQuery grid?


回答1:


Instead of handling the merging at the UI level, would it work to prepare the data source in such a way that you can just bind directly to it?

Basically create a view model that contains the data in an easier format to bind to.

GridView.DataSource() = vmAlreadyMergedAndReadtToGoOBject
GridView.DataBind();

I am not sure where you are getting the data from, but can't you build the object you bind to your grid programatically based on the result set you get back from your source (database?) Then if you you build that object by combining the rows values that are the same you could just bind the grid to it... Not entirely clear what you are doing, but this was the first thing that came to mind....




回答2:


for (i = PagSize; i <= dt.Rows.Count; i++)
{
    Curr = dt.Rows[i - 1]["Brand"].ToString();
    if (i < dt.Rows.Count)
    {
        Nxt = dt.Rows[i]["Brand"].ToString();
        diff = dt.Rows.Count - i;
        if (Curr != Nxt)
        {
            DctPaging.Add(PageNum, i);
            PageNum = PageNum + 1;
            i = i + PagSize;
            if (i >= dt.Rows.Count)
            {
                DctPaging.Add(PageNum, i);
                break;
            }
        }
    }
}

Reference Click Here



来源:https://stackoverflow.com/questions/9919434/asp-net-grid-paging-with-merged-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!