Re: Another GridView Bug -> PagerSettings.Visible



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
--
Milosz


"gerry" wrote:

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





"Milosz Skalecki [MCAD]" <mily242@xxxxxxxxxxxxxxxxx> wrote in message
news:BB6D6B13-996D-4776-B02B-E6AF35EA0B3E@xxxxxxxxxxxxxxxx
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

--
Milosz


"Peter Bromberg [C# MVP]" wrote:

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

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




"gerry" wrote:

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






.


Loading