DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 25 Jun 2007 12:43:01 -0700,    posted on: microsoft.public.dotnet.framework.aspnet.buildingcontrols        back       

Thread Index
  1    Chuck P am
          2    (Walter Wang [MSFT])
                 3    Chuck P am
                 4    (Walter Wang [MSFT])
                 5    Chuck P am
                 6    (Walter Wang [MSFT])
                        7    (Walter Wang [MSFT])


GridView Inherting   
I am inherting from the GridView and adding a property
ShowEditButton.  When this is true a new column is added with an Edit 
button.  I override the CreateColumns event to do this.

What is the difference between, storing the property value in a private 
local variable and ViewState?

In the design mode, I can change the property value and the display changes 
automagically. This happens whether I use viewstate or a private variable.  I 
guess if a controls property is changed in design mode some event fires and 
the control is rerendered???

At runtime I would like to change the value of the property in the PageLoad 
event.
However, the control doesn't seem to get rerendered.  Should I add something 
to the setter to get the control to rerender or something?

thanks,
Date:Mon, 25 Jun 2007 12:43:01 -0700   Author:  

RE: GridView Inherting   
Hi Chuck,

Unless the ShowEditButton property doesn't need to be persisted across 
postback, I think you will need to save it in ViewState.


Without complete code listing, I cannot tell exactly what's the cause of 
the issue, but I can point you to a complete working example on how to 
extend the GridView control:

#Cutting Edge: Extending the GridView Control -- MSDN Magazine, May 2006
http://msdn.microsoft.com/msdnmag/issues/06/05/CuttingEdge/


By the way, I've posted a reply to your previous post "GridView get ODS 
DataObjectTypeName", which I haven't seen your reply. Could you please tell 
me the status of it? Normally if you could post a reply to confirm the 
suggestion worked or not, we will easily track each post's status. Thanks.


Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
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.
Date:Tue, 26 Jun 2007 08:14:02 GMT   Author:  

RE: GridView Inherting   
I read that article.  I wonder how you could change whether you want the 
checkbox column or not at runtime.

If you have a property AddChkBoxColumn and you decided to change the value 
in the aspx. pageload,  I don't think it would do anything because the 
control has already been initialized and gotten viewstate stuff.  So the 
column is sitting their in the control.

In the property set, maybe what you do is call CreateColumns after the SET?
Date:Tue, 26 Jun 2007 15:22:03 -0700   Author:  

RE: GridView Inherting   
Hi Chuck,

You might have noticed that GridView's CommandField can dynamically 
show/hide various buttons:

    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (DataControlField dcf in GridView1.Columns)
        {
            CommandField cf = dcf as CommandField;
            if (cf != null)
            {
                cf.ShowEditButton = CheckBox1.Checked;
                break;
            }
        }


Internally, whenever a DataControlField is changed, GridView will set a 
flag RequiresDataBinding and calls DataBind again if needed.

To fix HotGridView.cs:

        public bool AutoGenerateCheckBoxColumn
        {
            get
            {
                object o = ViewState["AutoGenerateCheckBoxColumn"];
                if (o == null)
                    return false;
                return (bool)o;
            }
            set {
                if (AutoGenerateCheckBoxColumn != value)
                {
                    ViewState["AutoGenerateCheckBoxColumn"] = value;
                    if (base.Initialized)
                    {
                        base.RequiresDataBinding = true;
                    }
                }
            }
        }


(Note the sample code has some bug in OnPreRender, it should check whether 
or not FindControl returns null value)


With above change, you will be able to use code like this to dynamically 
show/hide the checkBox column:

GridView1.AutoGenerateCheckBoxColumn = CheckBox1.Checked;


Hope this helps.


Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
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.
Date:Thu, 28 Jun 2007 09:46:11 GMT   Author:  

RE: GridView Inherting   
thanks, Walter very very helpful.

I still don't fully understand the control life cycle.
Adding 
         if (base.Initialized)
                    {
                        base.RequiresDataBinding = true;
                    } 
to my properties seemed to do it.

I guess when you set that the gridivew regenerates its columns whenever it 
databinds.  When does it databind again? After all the postback events have 
happened and imeadiately before rendering?
Date:Thu, 28 Jun 2007 08:22:02 -0700   Author:  

RE: GridView Inherting   
For every control inherited from BaseDataBoundControl, it will call 
EnsureDataBound() in its OnPreRender(); this will make sure it calls 
DataBind() if RequiresDataBinding is set. The DataBind() will take care of 
regenerating required child controls.


Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
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.
Date:Fri, 29 Jun 2007 03:34:43 GMT   Author:  

RE: GridView Inherting   
Hi Chuck,

Thank you for the code. You asked a new question about the CheckBox 
column's state will get reset if the postback is caused by the update 
button.

After some debugging, I can see it's because the GridView gets re-bound to 
the data. This can also be reproduced by adding <asp:CommandField 
ShowEditButton="true" /> to the GridView: after you checked some CheckBox, 
if you edit a row, the checkbox states are reset since the GridView is 
re-bound. You will also notice that if you change the row's data in editing 
mode, and you click another row's "Edit" command again, the previously 
editing row's data will also get reset since the GridView will re-bind. 

I think is by design behavior and I doubt it's possible to persist the 
checkbox states when rebinding: what if the backend data is changed after 
rebinding? the previously checked rows' index may have changed too.



Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
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.
Date:Thu, 12 Jul 2007 09:45:26 GMT   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us