Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TreeView In GridView - OnTreeNodeCheckChanged event problem

2 views
Skip to first unread message

stephen

unread,
Apr 15, 2008, 6:33:57 PM4/15/08
to

Hi All,

I have a TreeView with CheckBoxes in one of the cells of a GridView and
OnTreeNodeCheckChanged event it does nothing (basically does not postback)
but if I have a button on the page then the OnTreeNodeCheckChanged get
triggered on PostBack. Can some please help me understand why? and how to
get it to postback from GridView itself? any sample articles would be
helpful....

Thanks again,
Stephen


Manish

unread,
Apr 16, 2008, 4:53:01 AM4/16/08
to
Hi Stephen,

You can try the following code to fire the treeNodeCheckChanged event. this
onlt fires when you change the checkbox and then click on the Item.

Dim tv As New TreeView
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

End Sub

Protected Sub tv_TreeNodeCheckChanged(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.TreeNodeEventArgs)
Response.Write(e.Node.Text)
End Sub
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
tv = e.Row.FindControl("TreeView1")
AddHandler tv.TreeNodeCheckChanged, AddressOf
tv_TreeNodeCheckChanged
End If
End Sub

Regards,
Manish
www.ComponentOne.com

stephen

unread,
Apr 16, 2008, 11:36:46 AM4/16/08
to

Hi Manish,

Thanks for the reply but it still did not trigger. If you can take a look at
the sample code and let me know that will be helpful.

<asp:GridView ID="GridView1" runat="server" .....
OnRowDataBound="GridView1_OnRowDataBound"
OnRowCreated="GridView1_OnRowCreated">
<Columns>
<asp:BoundField HeaderText="Order ID" DataField="OrderID" />
<asp:TemplateField>
<ItemTemplate>
<asp:TreeView ID="LinksTreeView" Font-Names="Arial" ForeColor="Blue"
runat="server" ShowCheckBoxes="All"
>
</asp:TreeView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Dynamic Populating the TreeView in Databound....

protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Web.UI.WebControls.TreeView myTreeView =
e.Row.FindControl("LinksTreeView") as System.Web.UI.WebControls.TreeView;
TreeNode myParentNode = new TreeNode();
myParentNode.Text = e.Row.Cells[0].Text;
myParentNode.Value = e.Row.Cells[0].Text;
myParentNode.SelectAction = TreeNodeSelectAction.Expand;
myParentNode.CollapseAll();
myTreeView.Nodes.Add(myParentNode);
PopulateOrderDetails(myParentNode);
}
}

protected void GridView1_OnRowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Web.UI.WebControls.TreeView tv = new
System.Web.UI.WebControls.TreeView();
tv =
(System.Web.UI.WebControls.TreeView)e.Row.FindControl("LinksTreeView");
tv.TreeNodeCheckChanged += new
TreeNodeEventHandler(tv_TreeNodeCheckChanged);
}
}

void tv_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
{
Response.Write(e.Node.Text);
}

I have tried to test the handler in both OnRowCreated and OnRowDataBound but
it does not work either way...

Thanks,
Stephen


"Manish" <Man...@discussions.microsoft.com> wrote in message
news:FCE98DEC-EC44-4313...@microsoft.com...

wis...@googlemail.com

unread,
Apr 17, 2008, 12:51:16 AM4/17/08
to
Hi Stephen,

The TreeView only populates CheckBoxes, but without a corresponding
OnClick event. And there is no such thing as AutoPostBack for
TreeViews. You would have to add OnClick events on your own in
Javascript. For a treatment of the subject and a possible solution ,
visit this thread:

http://forums.asp.net/p/643832/645130.aspx#645130

============
Regards,
Steve
www.stkomp.com

stephen

unread,
Apr 22, 2008, 6:24:20 PM4/22/08
to
Hi,

Thanks for all your replies.

Stephen

<wis...@googlemail.com> wrote in message
news:3ea57f76-e77f-4007...@k37g2000hsf.googlegroups.com...

0 new messages