4
如何在TreeView
控件中檢查TreeNode
複選框時自動回發到服務器?ASP.NET TreeView:檢查後回發更改?
如何在TreeView
控件中檢查TreeNode
複選框時自動回發到服務器?ASP.NET TreeView:檢查後回發更改?
對不起,沒有自動回
你可以用簡單的JavaScript添加此行爲
你應該檢查這篇文章 http://forums.asp.net/p/1109288/1888180.aspx
<script language="javascript" type="text/javascript">
function postBackByObject()
{
var o = window.event.srcElement;
if (o.tagName == "INPUT" && o.type == "checkbox")
{
__doPostBack("","");
}
}
</script>
爲了讓事情使用jQuery現代化一點:
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:TreeView ID="TVP" runat="server">
\t \t ...
</asp:TreeView>
<asp:Button ID="BTVPNC" runat="server" style="display: none;" />
</ContentTemplate>
</asp:UpdatePanel>
和VB.NET代碼背後:
Private Sub TVP_PreRender(sender As Object, e As EventArgs) Handles TVP.PreRender
Dim js As String = "$('#" + Me.TVP.ClientID + "').find('input[type=""checkbox""]')"
js += ".bind('change',function(){" + Me.ClientScript.GetPostBackEventReference(Me.BTVPNC, "") + ";});"
ScriptManager.RegisterStartupScript(Me.TVP, Me.TVP.GetType(), "TVP_NodeCheckAutoPostBack", js, True)
End Sub
Private Sub TVP_TreeNodeCheckChanged(sender As Object, e As TreeNodeEventArgs) Handles TVP.TreeNodeCheckChanged
\t 'Handle your TreeView NodeChecked with AutoPostBack event here.
End Sub