Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

TreeView In GridView - OnTreeNodeCheckChanged event problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
stephen - 15 Apr 2008 23:33 GMT
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 - 16 Apr 2008 09:53 GMT
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

> Hi All,
>
[quoted text clipped - 7 lines]
> Thanks again,
> Stephen
stephen - 16 Apr 2008 16:36 GMT
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

> Hi Stephen,
>
[quoted text clipped - 39 lines]
>> Thanks again,
>> Stephen
wisccal@googlemail.com - 17 Apr 2008 05:51 GMT
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

> Hi Manish,
>
[quoted text clipped - 103 lines]
> >> Thanks again,
> >> Stephen
stephen - 22 Apr 2008 23:24 GMT
Hi,

Thanks for all your replies.

Stephen

> Hi Stephen,
>
[quoted text clipped - 127 lines]
>> >> Thanks again,
>> >> Stephen

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.