Another GridView Bug -> PagerSettings.Visible

G

gerry

The PagerSettings.Visible property is not being handled properly by the
GridView control.
The value assigned to this property is not applied until after a postback.
Simplest test :
.aspx containing a single gridview - enable paging and give enough data
to page.
add checkbox with auto postback enable
add button with auto postback enable
in the GridView1_PreRender method add the following :
GridView1.HeaderRow.Enabled =
GridView1.PagerSettings.Visible =
CheckBox1.Checked;
note that the header should be enabled when the pager is visible and the
header should be disabled whetn the pager is hidden.

When you 1st view the page the header is disabled ( correct ) and the pager
is visible ( incorrect )
click the button and now the the header is disabled ( correct )and the pager
is hidden ( correct )
click the button as many times as you like , things remain as they shoud be.

Click the checkbox - now the header is enabled ( correct ) and the pager is
still hidden ( incorrect )
click the button and now the the header is enabled ( correct ) and the pager
is visible (correct )
click the button as many times as you like , things remain as they shoud be.

repeated clicking of the checkbox results in the header and pager being in
opposite 'phase'.

Having written my share of custom web controls, it is pretty obvious what
the problem is.


Has this been fixed with SP1 ? I am currently trying to install the update
but after about 6 hours I am not having much success.


Gerry
 
G

Guest

Gerry,
You should look for this in the Product Feedback site, for a couple of
reasons:
1) other people may have already submitted it (or something very similar)
and you can see the status of the alleged "bug" - including workarounds, if
any.
2) If it's a legitimate bug and nobody has submitted it, you have the honor
of being the first.

This page lists the different feedback sites by technology:

http://connect.microsoft.com/Main/content/content.aspx?ContentID=2220

Cheers,
Peter
 
G

Guest

Hi Gerry,

In addtion to Peter's comments, whilst data has been bound, all rows have
been already created based on values you provider at the binding stage (if
PagerSetting.Visible was set to false, pager was not rendered, and even if
you change it to true later in page execution it won't force gridview to show
pager). It's also true for postback, because gridview rebuilds itself based
on information stored in viewstate. To resolve the problem, you need to
rebind the data again:

// if autpostback is set to true you can handle CheckChanged event
protected void myCheckBox_CheckedChanged(object sender, EventArgs e)
{
bool checked = ((CheckBox) sender).Checked;

myGridView.PagerSettings.Visible = checked; // or !checked;
myGridView.DataSource = dataSource;
myGridView.dataBind();
}

Hope this helps
 
G

gerry

I'm not sure if you are saying that this not a bug - if so i beg to disagree
or at least to say that this a very very poor design.
Why handle the PageSettings property any different than any other property
on the control ? We can set any other property in PreRender and have it take
effect on the current request without requiring a post back or a rebind.
The real problem is that the designers of this control decided to treat the
PagerRow different than the other non-data rows - HeaderRow & FooterRow.
My workaround for this was to have the PagerSettings.Visible property always
set to true ( which should not be required ) and capture the pager row
object in the RowCreated event, then I use this PagerRow object to set pager
visibility rather than the PagerSettings property whihc is then consistant
with how we handle the properties of the HeaderRow & FooterRow.
The PagerRow should have been setup as an exposed property the same as
HeaderRow & FooterRow - I don't see any good reason why it wasn't.

Gerry
 
G

gerry

After looking at subclassing the GridView control to fix this short-coming ,
it appears that maybe the problem is that the PagerSettings.PropertyChanged
event is never fired
Accoroding to the docs this is where the rebind should be happening with
databound controls.

So for now my subclass handles the PagerRow property under the resttriction
that PagerSettings.Visible is not used at runtime.

Gerry
 
G

gerry

after more digging, i have dropped the subclass altogether as it turns out
that there is in fact a PagerRow object - more precisely there are 2 of them
TopPagerRow & BottomPagerRow.

For now I will ignore the PagerSettings.Visible property and use the
PagerRow properties to set their visible property.

Gerry
 
G

Guest

I have a BoundField column which I am dynamically adding to the GridView.

BoundField boundField_Committed_date = new BoundField();
boundField_Committed_date.DataField = "Committed_date";
boundField_Committed_date.HeaderText = "Committed Dt";
boundField_Committed_date.DataFormatString = "{0:d}";
boundField_Committed_date.HtmlEncode = false;
boundField_Committed_date.SortExpression = "Committed_date";

I want to have the Visible property coming from the database and
automatically binded. Visible property of course does not accept a Column
Name. Is there any work around?
 
G

Guest

Good morning Gerry,

I disagree with you at some point. GridView control is based on templates
and a data source. Dealing with data you have to consider it's only known at
binding stage regardless if you use data table, data set or data reader. Most
of the content within a template is based on data and in most cases binding
stage is the only time you can build the control structure. And pager is a
perfect example because it linked straight to the data - it can only be
displayed if grid views contains any rows, it has to consider number of pages
etc., not as for footer and header, they can be shown regardless if
underlying data source contains any results. That’s why disagree with
statement "…The real problem is that the designers of this control decided to
treat the PagerRow different than the other non-data rows - HeaderRow &
FooterRow…", because it a hybrid between data row and non data row :)

Best Regards
 
G

gerry

Hi Milisz,
I disagree with your disagreement. ;-) A pager row is no more tied to the
data binding process than the header row especially if you have
AutoGenerateColumns set to true.
As it turns out I was partly wrong , as I stated in a followup post, the
pager rows are treated the same as the header and footer rows AS LONG AS you
always have the PagerSettings.Visible property set to true. So the real
problem is how the that the PagerSettings.Visible property is applied - if
you ignore it and use the actual PagerRow object(s) to set pager visiblility
then everything works as it should. imo , the pager row object(s) should be
created regardless of the PagerSettings.Visible property value and this
value should be applied to the created objects. The way this control works
, the PagerSettings.Visible property should have been called
PagerSettings.Exists. Visibility is a UI property, not a DB property
Gerry
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top