Last post Sep 06, 2007 07:33 PM by lya0503
Aug 30, 2007 02:22 PM|lya0503|LINK
I have gridview on one web page. There is treeview under gridview.
Everytime when checkbox is checked, the checkednodes.count is always zero.
It seems like checked can not be detected.
Is anybody know the reason?
<asp:GridView ID="gridView1" EnableViewState="true" DataSourceID="SqlDataSource1"
<asp:TreeView ID="ID" OnTreeNodeCheckChanged="OnCheckChanged"
OnAdaptedTreeNodeCheckChanged="OnCheckChanged" cssclass="treeview" NodeStyle-Width="100" AdapterEnabled="false"
OnSelectedNodeChanged="tv_SelectedNodeChanged" ShowLines="true" runat="server"></asp:TreeView>
Thanks in advance.
Sep 01, 2007 08:40 PM|Russ Helfand|LINK
The way that the TreeView adapter deals with updating the "checked" state of items upon postback is encapsulated in the file App_Code\Adapters\TreeViewAdapter.cs. You'll find a method called UpdateCheckmarks. It does... well, pretty much what you'd expect.
You'll notice that this method is called during the RaisePostDataChangedEvent (that is there to support the fact that this adapter's class is declared to support the IPostBackDataHandler interface,
If I were you, I'd follow my hunch that what you are running into is a problem wherein you are examining the state of the checkmarks before they've been updated by the adapter's UpdateCheckmarks method. You might test this theory by doing your work in your
Page's PreRender event handler, rather than, say, it's Load handler, which comes much earlier than PreRender in the Page's life cycle. By deferring the logic that you need to execute (until later in the Page lifecycle, like during PreRender) you give the adapter
a chance to update the checkmarks. I think (this is the guess part) that the Page's sequence is:
(with several events inserted in between)
So if you can do your work during PreRender you may find that magically the checkmark count is correctly set at that point in the game.
There have been others (particularly a group from Germany) who have found fault with the fact that the TreeView adapter tends to do its state management too late the game, too late in the Page lifecycle. I agree. I simply didn't figure out a way to get the
TreeView to get notified of the PostBack data earlier in the lifecycle than RaisePostDataChangedEvent. So, for now, I tend to think that the solution to your problem will be to defer doing your work until later in the cycle.
If that doesn't help... then I suggest you run the samples in VS (or VWD) locally. The tutorial shows you how (see
www.asp.net/cssadapters). Put some break points in UpdateCheckmarks and see what's going on in there. If it is properly updating the checkmarks then fundamentally your page can do something similar at any point later
in the processing of the page.
Clear as mud??? Good luck. Let me know how it goes.
Sep 06, 2007 07:33 PM|lya0503|LINK
Thank you so much for your reply.
What happened is I have one treeview item on my gridview, I add treenode from codebehind and showcheckbox=true.
when checkbox is checked, the checkmark is there. I have start button. When user click start butten, then application will look for this checked item to start job.
Somehow the checkbox was not found.
Hope I explained my problem clearly. But same time I will follow you suggestion to do some testing. I will let you know.