制作一个简单的服务器端控制

2016-01-29 17:16 7 1 收藏

制作一个简单的服务器端控制,制作一个简单的服务器端控制

【 tulaoshi.com - ASP 】

  2000082805.aspx
-------------------------------------------------------------
<%@ Register TagPrefix="CJ" Namespace="cjServerControls" %
<html
  <head
  </head
  <body

    <form method="post" action="2000082605.aspx" runat="server"
<CJ:xmlDocReader  listText="au_id" listValue="au_id" runat="server"
path="C:InetpubwwwrootmyASPtutorialsauthors.xml" /
    </form

  </body
</html


2000082805a.cs
-------------------------------------------------------------
using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace cjServerControls
{
public class xmlDocReader : Control, INamingContainer
{
string _xmlPath;
string _listID;
string _listValue;

public string Path
{
get { return _xmlPath; }
set { _xmlPath = value; }
}

public string listText
{
get { return _listID; }
set { _listID = value; }
}

public string listValue
{
get {return _listValue; }
set {_listValue = value; }
}

//Were are creating a member here so we can access it throughout the class
DropDownList _DDL;
DataGrid _DG;
FileStream fs;
StreamReader sr;
DataSet ds;
protected override void PreRender()
{
if (Page.IsPostBack) {
DataView dv = new DataView(ds.Tables[0]);
dv.RowFilter = listValue + "='" + _DDL.SelectedItem.Text + "'";
_DG = new DataGrid();
_DG.DataSource = dv;
_DG.DataBind();
Controls.Add(_DG);
}
}


protected override void CreateChildControls()
{
fs = new FileStream(Path, FileMode.Open, FileAccess.Read);
sr = new StreamReader(fs);
ds = new DataSet();
ds.ReadXml(sr);
fs.Close();

_DDL = new DropDownList();
_DDL.DataTextField = listText;
_DDL.DataValueField = listValue;
_DDL.AutoPostBack = true;
_DDL.DataSource = ds.Tables[0].DefaultView;
_DDL.DataBind();
Controls.Add(_DDL);


}
}
}

authors.xml
-------------------------------------------------------------
<root
<schema id="DocumentElement" targetNamespace="" xmlns="http://www.w3.org/1999/XMLSchema"
xmlns:xdo="urn:schemas-microsoft-com:xml-xdo" xdo:DataSetName="DocumentElement"
    <element name="Table"
        <complexType content="elementOnly"
            <element name="au_id" type="string"</element
            <element name="au_lname" type="string"</element
            <element name="au_fname" type="string"</element
            <element name="phone" type="string"</element
            <elem

来源:https://www.tulaoshi.com/n/20160129/1500827.html

延伸阅读
标签: ASP
  实现健壮性能的规则 Hank Marquis 来自于Enterprise Solutions for Microsoft BackOffice and Windows NT Magazine 原稿地址:http://www.microsoft.com/china/technet/intranet/sevstep.asp 在你的服务器上安装了微软IIS(Internet Information Server),你就可以发挥ASP(Active Server Pages)的优势了,ASP利用ActiveX组件来为你的网...
标签: ASP
  客户端和服务器通信可采用一种自定义协议。然而,SOAP为此提供了一种灵活的、易于扩展的和简单的方案。使用XMLHTTP对象,客户端浏览器可请求在服务器上执行一个ASP,并等候服务器的响应以继续。由于原始客户端网页没有卸载,所以对客户来说,整个过程都是透明的,而且速度一般都非常快。   下面通过几个示范网页来探讨该技术...
标签: PHP
  假设有10个网站,分布在各地,它们的库存要同步,而数据库不支持远程连接。 我们要实时地取得服务器的库存数,可以通过很多种方法,我所知道的有以下几种: ·CURL方式 ·SOCKET方式 ·PHP5中的SOAP方式 以下分别给出示例来实现它: CURL方式 client.php <?php $psecode = ’NDE005’;...
     页面代码:   <script type="text/javascript"    function ReceiveServerData(rValue)    {    alert(rValue);    }    </script   <input id="Button1" type="button" value="button" onclick ="CallServe...
代码如下: using System; using System.Collections; using System.Text; using System.IO; using System.Collections.Specialized; using System.Text.RegularExpressions; using System.Diagnostics; namespace CSS { public class App { public static void Main(string[] args) { //初始化CSS解析器 CssDocument doc = ne...

经验教程

959

收藏

64
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部