Treeview 동적 으로 사용자 컨트롤 값 과 값 을 추출 하 는 인 스 턴 스 코드 를 추가 합 니 다.
주요 기능:하위 노드 의 checkbox 를 선택 하면 오른쪽 에 이 노드 의 정 보 를 동적 으로 불 러 옵 니 다.TextBox 가 나타 나 면 사용자 가 노드 의 값 을 입력 하고 저장 단 추 를 누 르 면 텍스트 상자 의 값 을 해당 노드 에 저장 합 니 다.asp 실행 ascx 페이지 의 이벤트 와 값 을 추출 합 니 다.이것 은 프론트 데스크 의 코드 입 니 다:CustomXMLmanager.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomXMLmanager.aspx.cs" Inherits="usexml.CustomXMLmanager" %>
<%@ Register src=http://www.cnblogs.com/panan/archive////"Custom.ascx" tagname="Custom" tagprefix="uc" %>
<!DOCTYPE html PUBLIC "-//WC//DTD XHTML .0 Transitional//EN" "http://www.w.org/TR/xhtml/DTD/xhtml-transitional.dtd">
<html xmlns="http://www.w.org//xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script language="javascript" type="text/javascript">
//
function postBackByObject() {
var o = window.event.srcElement;
if (o.tagName == "INPUT" && o.type == "checkbox") {
__doPostBack("", "");
}
}
</script>
<form id="form" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
<table width="%" style="border: px dotted #00"><tr><td width="%">
<asp:TreeView ID="TreeView" runat="server" ImageSet="Simple" ShowCheckBoxes="Leaf"
ShowLines="True"
ViewStateMode="Enabled">
<HoverNodeStyle Font-Underline="True" ForeColor="#DD" />
<Nodes>
<asp:TreeNode Text=" " Value=http://www.cnblogs.com/panan/archive////" ">
<asp:TreeNode Text=" " Value=http://www.cnblogs.com/panan/archive////" "></asp:TreeNode>
<asp:TreeNode Text=" " Value=http://www.cnblogs.com/panan/archive////" "></asp:TreeNode>
<asp:TreeNode Text=" " Value=http://www.cnblogs.com/panan/archive////" "></asp:TreeNode>
<asp:TreeNode Text=" " Value=http://www.cnblogs.com/panan/archive////" "></asp:TreeNode>
<asp:TreeNode Text=" " Value=http://www.cnblogs.com/panan/archive////" "></asp:TreeNode>
</asp:TreeNode>
</Nodes>
<NodeStyle Font-Names="Tahoma" Font-Size="pt" ForeColor="Black"
HorizontalPadding="0px" NodeSpacing="0px" VerticalPadding="0px" />
<ParentNodeStyle Font-Bold="False" />
<SelectedNodeStyle Font-Underline="True" ForeColor="#DD"
HorizontalPadding="0px" VerticalPadding="0px" />
</asp:TreeView>
</td>
<td style="background-color: #00; width: px"></td>
<td>
<asp:PlaceHolder ID="PlaceHolder" runat="server"></asp:PlaceHolder>
</td>
</tr></table>
<div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div align="center"><asp:Button ID="Button" runat="server" Text=" "
onclick="Button_Click" /></div>
</form>
</body>
</html>
이것 은 백 스테이지 코드 입 니 다:CustomXMLmanager.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
namespace usexml
{
public partial class CustomXMLmanager : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
//if (ViewState["node"] != null)
//{
// nodes();
//}
nodes();
}
TreeView.Attributes.Add("onclick", "postBackByObject()");
}
private void nodes()
{
int tg = 0;
foreach (TreeNode nod in TreeView.CheckedNodes)
{
nod.Target = tg.ToString();
Custom uc = (Custom)LoadControl("Custom.ascx");
uc.Nodname = nod.Text;
uc.Nodvalue = https://www.jb51.net/panan/archive////nod.Value;
uc.Nodetag = nod.Target;
PlaceHolder.Controls.Add(uc);
tg++;
}
}
protected void Button_Click(object sender, EventArgs e)
{
for (int i = 0; i < PlaceHolder.Controls.Count; i++)
{
UserControl uc = (UserControl)PlaceHolder.Controls[i];
Type ucType = uc.GetType();
// MethodInfo .
MethodInfo UcMethod = ucType.GetMethod("GetText");// Button_Click 。
// .
object[] argumentArrray = new object[0];
UcMethod.Invoke(uc, new object[0]);// 。 !!。
foreach (TreeNode nod in TreeView.CheckedNodes)
{
PropertyInfo UctextName = ucType.GetProperty("PicName");
PropertyInfo tag = ucType.GetProperty("Nodetag");
if (nod.Target == tag.GetValue(uc, null).ToString())
{
nod.Value = https://www.jb51.net/panan/archive////UctextName.GetValue(uc, null).ToString();// 。 page 。
}
}
}
}
}
}
이것 은 사용자 컨트롤 의 프론트 데스크 입 니 다:Custom 2.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Custom2.ascx.cs" Inherits="usexml.Custom2" %>
<div>
<asp:Label ID="Label1" runat="server" Text="Label" ForeColor="#006666"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
:<asp:Label ID="Label2" runat="server" Text="Label" ForeColor="#003366"></asp:Label>
</div>
이것 은 사용자 컨트롤 의 백 스테이지 입 니 다:Custom 2.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace usexml
{
public partial class Custom2 : System.Web.UI.UserControl
{
private string nodname = "";
public string nodvalue = https://www.jb51.net/panan/archive/2011/12/28/"";
private string nodtag = "";
private string picname = "";
public string Nodname
{
get
{
return nodname;
}
set
{
nodname = value;
}
}
public string Nodvalue
{
get
{
return nodvalue;
}
set
{
nodvalue = https://www.jb51.net/panan/archive/2011/12/28/value;
}
}
public string Nodetag
{
get
{
return nodtag;
}
set
{
nodtag = value;
}
}
public string PicName
{
get { return picname; }
set { picname = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = nodname+":";
Label2.Text = nodvalue;
}
public void GetText()
{
picname = TextBox1.Text;
TextBox1.Text = "";
Label2.Text = picname;
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Spring Data JPA의 동적 조회 인스턴스예를 들어 프론트에 여러 가지 조건이 있는데 이런 조건은 대부분이 선택할 수 있다. hibernate를 사용할 때 조건을 판단하여 SQL(HQL)을 연결할 수 있다. 만약 컴파일러가 조회에 대해 문법 정확성을 검사할...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.