datagrid sort and headers on every page

S

sam

Hello Group,
Havent had luck posting it to
microsoft.public.dotnet.framework.aspnet.datagridcontrol group. Excuse
me for the cross posting.
I have a datagrid which needs to be split into multiple
pages when printing along with headers on every page. I came up with
this routine below which adds 2 rows - one with datagrid headers and
the other is also a headers which consists other related information.
The 2 rows(headers) needs to be inserted for every
iMaxLines(constant-say 40) lines. When I debug, the headers get
inserted at correct positions but when doing a databind to
the datagrid(dgWIP), the headers show up at the very top of the
datagrid.
Not quite sure how to insert the headers and still retain
the sortorder. The initial databind is done as the addheaderlines
function is called after a postback and I need to retain the
sortorder. The sort is
disabled after the intial databind. Still cant understand, why are the
2 inserted rows shifted to the top of
the datagrid.
Any help on this issue would be great!!
cODE:

Private Sub addHeaderLines(ByVal dt As DataTable, ByVal part As
Int16)

Dim drHeader, drBlank As DataRow
Dim count, repeatCount, upperBound As Integer
Dim dvWIP As DataView

dvWIP = dt.DefaultView

dgWIP.DataSource = dvWIP
dvWIP.Sort = Me.SortColumn & " " & Me.SortOrder
dgWIP.DataBind()
dgWIP.AllowSorting = False


repeatCount = iMaxLines
upperBound = dt.Rows.Count

count = 0
While count <= upperBound

' If count Mod iMaxLines = 1 And count > 1 Then
If repeatCount = 1 Then
drBlank = dt.NewRow
drHeader = dt.NewRow
If part = 3 Then
drBlank(2) = "hd1"
drHeader(2) = "hd2"
Else
drBlank(0) = "hd1"
drHeader(0) = "hd2"
End If
dt.Rows.InsertAt(drBlank, count)
dt.Rows.InsertAt(drHeader, count + 1)
'count += 1
upperBound += 2
repeatCount = iMaxLines

Else

repeatCount -= 1

End If

count += 1

End While


dgWIP.DataSource = dt ' headers get shifted here...
dgWIP.DataBind()


End Sub

Thanks a bunch,
Sam.
 
C

Cor Ligthert

Sam,

What you are doing is not crossposting however multiposting, it had been
crossposting when you had send this message to more newsgroups in one time,
wherefore can be a good reason and mostly when not used wrong does not give
any complain.

Multiposting is more messages to more newsgroups, what mean when somebody
sees that and has searched for a solution for you can make im angry.

However your problem.

Did you already look at custompaging the datagrid, that is made for your
question in my opinion and very nice

http://msdn.microsoft.com/library/d...ntrolsdatagridclassallowcustompagingtopic.asp

I hope this helps?

Cor
 
S

sam

Cor,
Thanks for your reply. I guess you have misinterpreted my scenario.
CustomPaging is not what I am looking for. I do not use paging in the
datagrid and display all the rows in the same page. But when one needs
to print the page, I have a link "print version" which would have to
split the datagrid into multiple pages(according to the page size say
40 rows in one page) with headers prepended on each page. Hope, this
makes my case better if not clear.

Thanks,
Sam.
 
C

Cor Ligthert

Hi Sam,

Trying to get it clear for me as well.
I assume now that you want to make in one time more sorted datatables that
you can use as the datasources for your datagrid. While the first row
contains header information and the rest normal. Problem for me with this is
that the datatable than has to contain all string columns what you probably
do not have.

What is probably more easier, is adding a column to your datatable, fill
that by going in a for index loop through it, and than use the dataview
again, where you can set a rowfilter accoording to the page height.

Before you go looking for that, you cannot add that column and using an
expression to fill the numbers and either you can not use the columnseed to
add that number.

When you need some code tell it than, for the first there should of course
the condition I wrote be fullfiled.

For the next time, a more proper newsgroup for this is in my opinion
microsoft.public.dotnet.framework.adonet,
because the datatable and dataview are parts of ADONET).

I hope this helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top