问题
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