PC Review


Reply
Thread Tools Rate Thread

When I add an extra header row with spanning, my row data disappears one at a time

 
 
ShamusFu
Guest
Posts: n/a
 
      15th Jul 2003
I added a second header row to my datagrid with spanned columns for
looks, but it seems when I post back from other buttons on the page,
the bound data in the rows disappears one at a time. The data is not
deleted, since when I edit the DG it all comes back, but it looks
ugly. You can press a submit button on the page for some other action
and the row data disappears one at a time. The rows are still there,
they just have blank cells.

Here is the code for adding another header row and spanning:


Dim dgitem As New DataGridItem(0, 0, ListItemType.Header)

Dim emptycell As New TableCell
emptycell.ColumnSpan = 2 'Set it to the colspan that you want
emptycell.Text = ""

Dim headcell As New TableCell
headcell.ColumnSpan = 3 'Set it to the colspan that you want
headcell.Text = "Head circ.(ofc)"
headcell.Font.Bold = True

Dim lenghtcell As New TableCell
lenghtcell.ColumnSpan = 3 'Set it to the colspan that you want
lenghtcell.Text = "Length/height"
lenghtcell.Font.Bold = True

Dim weightcell As New TableCell
weightcell.ColumnSpan = 3 'Set it to the colspan that you want
weightcell.Text = "Weight"
weightcell.Font.Bold = True

Dim bmicell As New TableCell
bmicell.ColumnSpan = 2 'Set it to the colspan that you want
bmicell.Text = "BMI"
bmicell.Font.Bold = True

Dim editcell As New TableCell
editcell.ColumnSpan = 2 'Set it to the colspan that you want
editcell.Text = ""
dgitem.Cells.Add(emptycell)
dgitem.Cells.Add(headcell)
dgitem.Cells.Add(lenghtcell)
dgitem.Cells.Add(weightcell)
dgitem.Cells.Add(bmicell)
dgitem.Cells.Add(editcell)
dgPatientData.Controls(0).Controls.AddAt(0, dgitem)
 
Reply With Quote
 
 
 
 
Kathleen Dollard
Guest
Posts: n/a
 
      16th Jul 2003
I suspect your problem is unrelated to the spanned columns. Can you remove
that and see if it works as you'd expect?

Kathleen

"ShamusFu" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I added a second header row to my datagrid with spanned columns for
> looks, but it seems when I post back from other buttons on the page,
> the bound data in the rows disappears one at a time. The data is not
> deleted, since when I edit the DG it all comes back, but it looks
> ugly. You can press a submit button on the page for some other action
> and the row data disappears one at a time. The rows are still there,
> they just have blank cells.
>
> Here is the code for adding another header row and spanning:
>
>
> Dim dgitem As New DataGridItem(0, 0, ListItemType.Header)
>
> Dim emptycell As New TableCell
> emptycell.ColumnSpan = 2 'Set it to the colspan that you want
> emptycell.Text = ""
>
> Dim headcell As New TableCell
> headcell.ColumnSpan = 3 'Set it to the colspan that you want
> headcell.Text = "Head circ.(ofc)"
> headcell.Font.Bold = True
>
> Dim lenghtcell As New TableCell
> lenghtcell.ColumnSpan = 3 'Set it to the colspan that you want
> lenghtcell.Text = "Length/height"
> lenghtcell.Font.Bold = True
>
> Dim weightcell As New TableCell
> weightcell.ColumnSpan = 3 'Set it to the colspan that you want
> weightcell.Text = "Weight"
> weightcell.Font.Bold = True
>
> Dim bmicell As New TableCell
> bmicell.ColumnSpan = 2 'Set it to the colspan that you want
> bmicell.Text = "BMI"
> bmicell.Font.Bold = True
>
> Dim editcell As New TableCell
> editcell.ColumnSpan = 2 'Set it to the colspan that you want
> editcell.Text = ""
> dgitem.Cells.Add(emptycell)
> dgitem.Cells.Add(headcell)
> dgitem.Cells.Add(lenghtcell)
> dgitem.Cells.Add(weightcell)
> dgitem.Cells.Add(bmicell)
> dgitem.Cells.Add(editcell)
> dgPatientData.Controls(0).Controls.AddAt(0, dgitem)



 
Reply With Quote
 
New Member
Join Date: Jun 2007
Posts: 1
 
      27th Jun 2007
I have the EXACT same problem, but I know a little bit about what's causing it.

I'm very sure problem isn't related to the fact that we're using spanned columns, but that we're adding rows dynamically to the datagrid. When you postback, the server doesn't know that those extra rows exist due to the fact that they were added dynamically to the controls collection, hence that row's information is lost on postback (including the fact that it was a header row, it gets wiped blank and becomes the new first item row, pushing the last item row out of the bottom of the table).

I'm guessing that you're re-creating your dynamic header row on every postback? If you want to test out what I've said, only add your dynamic header row once (when the datagrid is initialised). On the first postback the new header row will disappear, becoming a new blank row just underneath the original header and pushing your last row of data out of the bottom of the table. Since your heading row hasn't been re-created this time, subsequent postbacks will not create any more blank rows.



Phew, after I've said all of that, the bad news is that I have no idea how to fix this problem other than not adding rows dynamically in the first place. In my case though, adding dynamic rows to the heading is unavoidable... If anybody else here has any ideas of how to stop the dynamic row's data from being lost on postback, please let us know!

EDIT: Well... I didn't check the date of the original message now, did I... Regardless, if anyone has a solution to this problem, I'd greatly appreciate it. I've been searching for a solution to this problem for days.

EDIT 2: Well what do you know, after two and a half days of non-stop searching I finally found the answer.

Rather than adding new header rows to the DataGrid's control collection, I'm overriding the DataGrid's header item rendering method, and injecting my own HTML code directly instead. This way, I need to rebind the DataGrid after each postback, but atleast I'm not losing data anymore.

See the following link for more information: http://www.codeproject.com/aspnet/Me...gridHeader.asp

I hope that this helps the next person who encounters the same problem as me.

Last edited by Michael Erak; 27th Jun 2007 at 05:59 AM..
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Group Header Splits When Spanning Multiple Pages coder09 Microsoft Access Reports 26 31st Jul 2009 03:19 AM
find the difference between start time and end time when spanning. wahoos Microsoft Excel Misc 8 18th Jan 2008 06:02 PM
Extra data comes at time of serialize DataSet IMS.Rushikesh@gmail.com Microsoft Dot NET 0 25th Aug 2005 02:55 PM
Time calculation (in hh.mm) spanning more than one day =?Utf-8?B?ZHRlbmN6YQ==?= Microsoft Excel Misc 8 16th Aug 2005 09:49 PM
Deleting extra space at data entry time ChelleV Microsoft Access Database Table Design 7 17th Dec 2003 07:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:41 PM.