有没有办法知道回发是由展开还是折叠树视图控件生成的?
问问题
414 次
2 回答
0
你可以试试这个
if (IsPostBack)
{
string ControlID = string.Empty;
if (!String.IsNullOrEmpty(Request.Form["__EVENTTARGET"]))
{
ControlID = Request.Form["__EVENTTARGET"];
}
}
来源: http: //www.codeproject.com/Articles/134614/Way-To-Know-Which-Control-Has-Raised-PostBack
另一个链接: http: //www.codeproject.com/Tips/82086/How-to-know-which-control-has-raised-a-postback
于 2013-08-19T12:58:28.600 回答
0
您的 ASP.NET 树视图:
<asp:TreeView ID="tvMain" runat="server" ExpandDepth="10" OnTreeNodeExpanded="tvMain_TreeNodeExpanded" OnTreeNodeCollapsed="tvMain_TreeNodeCollapsed">
<RootNodeStyle Font-Bold="true" />
<Nodes>
<asp:TreeNode Text="Root" Value="Root">
<asp:TreeNode Text="Link2" Value="Link1"></asp:TreeNode>
<asp:TreeNode Text="Link2" Value="Link2"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
您背后的代码:
Protected Sub tvMain_TreeNodeCollapsed(sender As Object, e As System.Web.UI.WebControls.TreeNodeEventArgs)
If Page.IsPostBack Then
If e.Node.Value.Equals("Root") Then
'Do your stuff'
End If
End If
End Sub
Protected Sub tvMain_TreeNodeExpanded(sender As Object, e As System.Web.UI.WebControls.TreeNodeEventArgs)
If Page.IsPostBack Then
If e.Node.Value.Equals("Root") Then
'Do your stuff'
End If
End If
End Sub
诀窍是处理 OnTreeNodeCollapsed 事件和 OnTreeNodeExpanded 事件。接下来,为根节点选择一个值 - 即第一个子节点和单个子节点。您将节点添加到根节点并确保它们具有与根节点不同的值。
于 2013-08-19T16:31:24.483 回答