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 said:
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,
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