Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > GridView override InitializePager columnSpan problem when using BoundField Visible=false

Reply
Thread Tools

GridView override InitializePager columnSpan problem when using BoundField Visible=false

 
 
J055
Guest
Posts: n/a
 
      06-08-2006
Hi

I have an overridden InitializePager method in my custom GridView. I use it
to add some page information to the pager row by splitting the table cell.
This works fine until I add either a BoundField or TemplateField where
visible is set to false.

This causes the two Table Cells of the pager row to have incorrect
columnSpans, e.g. where I have 6 columns and one invisible column (total 7)
the pager row will have a left cell with colspan="6" and a right cell with
colspan="4". If I change then visible attribute to true I get left cell with
colspan="3" and a right cell with colspan="4" which is correct.

I have know idea why this happens. When debugging I have found the
InitializePager method is called with columnSpan parameter set to the number
of columns including the invisible one (7).

Please help.
Thanks
Andrew

protected override void InitializePager(GridViewRow row, int columnSpan,
PagedDataSource pagedDataSource)

{

// call the base method first

base.InitializePager(row, columnSpan, pagedDataSource);

// create a new tablecell to contain the new page information

TableCell cell1 = new TableCell();

// divide the pager row in half

int ltSpan = (int)(columnSpan / 2);

int rtSpan = columnSpan - ltSpan;

// add the new label control with the new page info

cell1.Controls.Add(PageInfo(pagedDataSource.DataSo urceCount));

// add the new cell to the pager row and apply the ColumnSpan sizes

row.Controls.AddAt(0, cell1);

row.Cells[0].ColumnSpan = ltSpan;

row.Cells[1].ColumnSpan = rtSpan;

// pager buttons are now the right and page info on the left

row.Cells[1].HorizontalAlign = HorizontalAlign.Right;

}


 
Reply With Quote
 
 
 
 
J055
Guest
Posts: n/a
 
      06-11-2006
Hi

I've taken a different approach to get over the previous problem, however I
now get two new ones. This is the code:

protected override void OnRowCreated(GridViewRowEventArgs e)

{

switch (e.Row.RowType)

{

case DataControlRowType.Header:

if (SortExpression != String.Empty)

DisplaySortOrderImages(SortExpression, e.Row);

break;

case DataControlRowType.Pager:

Context.Trace.Warn("PagerRow");

if (DisplayPageInfo)

{

Table tbl = new Table();

tbl.CellSpacing = 0;

tbl.Width = Unit.Percentage(100);

tbl.Rows.Add(new TableRow());

tbl.Rows[0].Cells.Add(new TableCell());

tbl.Rows[0].Cells.Add(new TableCell());

tbl.Rows[0].Cells[0].Controls.Add(PageInfo(dataSourceRowCount));

tbl.Rows[0].Cells[1].HorizontalAlign = HorizontalAlign.Right;



foreach (Control ctrl in e.Row.Cells[0].Controls)

{

tbl.Rows[0].Cells[1].Controls.Add(ctrl);

}

e.Row.Cells[0].Controls.Add(tbl);

}

break;

default:

break;

}

base.OnRowCreated(e);

}


1. The new table does not get created when there is only one page, i.e. the
pager controls are not present. I still want to display the new table and
the contents of tbl.Rows[0].Cells[0].

2. The VS2005 IDE complains in page design mode - 'There was an error
rendering the control. Object reference not set to an instance of an
object'. However the code runs OK in the browser except for (1).

Even if the above code worked properly I rather have the code in my first
post work to avoid so many nested tables (It's not really how modern web
pages should be designed!).

Please help!
Andrew


 
Reply With Quote
 
 
 
 
J055
Guest
Posts: n/a
 
      06-12-2006
Hello

I've found what was causing the VS IDE to complain. It doesn't like me
writing out

Context.Trace.Warn("debug lines")
in my custom control OnRowCreated method. How would I know that? I still
need help with the other questions raised in my previous post.

Thanks

Andrew


 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      06-12-2006
Hello Andrew,

Thank you for posting.

It seems that you're still struggling with the custom Gridview with custom
paging functionality. As for your 3 questions, I've just done some research
and struggle against the GridView. here are some of the results I got:

1.This does be an existing issue, and based on my reseach upon gridview's
code, when there is only one page needed, the GridView's certain PagerRow
will be set to Visible=False, we can consider set it to true in our
override "CreateChildControls" method. e.g.

========================
protected override void CreateChildControls()
{
base.CreateChildControls();

if(!this.DesignMode)
Context.Response.Write("<br/>Count: " + this.PageCount);

if (this.PageCount == 1)
{

if ((this.PagerSettings.Visible) &&
(this.PagerSettings.Position == PagerPosition.Bottom))
{

BottomPagerRow.Visible = true;

}

}


}
==============================

2. As for the context null reference issue, it is because when in IDE, the
HttpContext is not available, the control is hosted in VS IDE(designer
host). We can simply add code to determine the current context such as

if(Context != null)
{

}

or
if(!this.DesignMode)
{

}

3. As for the further question you mentioned:

================
Even if the above code worked properly I rather have the code in my first
post work to avoid so many nested tables (It's not really how modern web
pages should be designed!).
===============

I'm still not quite clear on this, do you mean that the pager need to be
created each time the control is loaded(in each page request)? And you want
to only create it once?

Please feel free to let me know if there is anything I didn't get.


Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      06-14-2006
Hi Andrew,

Have you got any further ideas on this issue or does my last reply helps
you a little on this? If there is anything else we can help, please feel
free to post here.

Regards,

Steven Cheng
Microsoft MSDN Online Support Lead


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
GridView overriding InitializePager Andrew Robinson ASP .Net 2 04-13-2007 02:03 AM
How to edit in GridView using asp:BoundField-Urgent pls. reply asa =?Utf-8?B?U0RSb3k=?= ASP .Net 1 04-27-2006 11:40 AM
how to check columnspan in aspx page (not code behind) geronimi ASP .Net 0 01-02-2006 01:16 PM
Problem with OnItemCreated and InitializePager being called four times Bernal Schooley ASP .Net Datagrid Control 0 04-05-2004 02:51 PM
Columnspan in Datagrid ? ajaymehra ASP .Net 1 02-06-2004 09:35 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57