{"id":243258,"date":"2022-05-27T08:24:27","date_gmt":"2022-05-27T00:24:27","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=243258"},"modified":"2022-05-23T14:25:03","modified_gmt":"2022-05-23T06:25:03","slug":"asp-net-web","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/asp-net-web.html","title":{"rendered":"ASP.NET Web Forms – XML \u6587\u4ef6\u7b80\u4ecb"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nASP.NET \u662f\u4e00\u4e2a\u4f7f\u7528 HTML\u3001CSS\u3001JavaScript \u548c\u670d\u52a1\u5668\u811a\u672c\u521b\u5efa\u7f51\u9875\u548c\u7f51\u7ad9\u7684\u5f00\u53d1\u6846\u67b6\u3002\u6211\u4eec\u53ef\u4ee5\u7ed1\u5b9a XML \u6587\u4ef6\u5230\u5217\u8868\u63a7\u4ef6\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u4e00\u4e2a XML \u6587\u4ef6<\/strong><\/div>\n

\u8fd9\u91cc\u6709\u4e00\u4e2a\u540d\u4e3a \"countries.xml\" \u7684 XML \u6587\u4ef6\uff1a<\/p>\n

\r\n<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<countries>\r\n<country> \r\n<text>Norway<\/text> \r\n<value>N<\/value>\r\n<\/country>\r\n<country> \r\n<text>Sweden<\/text> \r\n<value>S<\/value>\r\n<\/country>\r\n<country> \r\n<text>France<\/text> \r\n<value>F<\/value>\r\n<\/country>\r\n<country> \r\n<text>Italy<\/text> \r\n<value>I<\/value>\r\n<\/country>\r\n<\/countries><\/pre>\n
\u7ed1\u5b9a DataSet \u5230 List \u63a7\u4ef6<\/strong><\/div>\n

\u9996\u5148\uff0c\u5bfc\u5165 \"System.Data\" \u547d\u540d\u7a7a\u95f4\u3002\u6211\u4eec\u9700\u8981\u8be5\u547d\u540d\u7a7a\u95f4\u4e0e DataSet \u5bf9\u8c61\u4e00\u8d77\u5de5\u4f5c\u3002\u628a\u4e0b\u9762\u8fd9\u6761\u6307\u4ee4\u5305\u542b\u5728 .aspx \u9875\u9762\u7684\u9876\u90e8\uff1a<\/p>\n

\r\n<%@ Import Namespace=\"System.Data\" %><\/pre>\n

\u63a5\u7740\uff0c\u4e3a XML \u6587\u4ef6\u521b\u5efa\u4e00\u4e2a DataSet\uff0c\u5e76\u5728\u9875\u9762\u7b2c\u4e00\u6b21\u52a0\u8f7d\u65f6\u628a\u8fd9\u4e2a XML \u6587\u4ef6\u8f7d\u5165 DataSet\uff1a<\/p>\n

\r\n<script runat=\"server\">\r\nsub Page_Load\r\nif Not Page.IsPostBack then   \r\ndim mycountries=New DataSet   \r\nmycountries.ReadXml(MapPath(\"countries.xml\"))\r\nend if\r\nend sub<\/pre>\n

\u4e3a\u4e86\u7ed1\u5b9a\u6570\u636e\u5230 RadioButtonList \u63a7\u4ef6\uff0c\u9996\u5148\u8981\u5728 .aspx \u9875\u9762\u4e2d\u521b\u5efa\u4e00\u4e2a RadioButtonList \u63a7\u4ef6\uff08\u4e0d\u5e26\u4efb\u4f55 asp:ListItem \u5143\u7d20\uff09\uff1a<\/p>\n

\r\n<html>\r\n<body>\r\n<form runat=\"server\">\r\n<asp:RadioButtonList id=\"rb\" runat=\"server\"\r\nAutoPostBack=\"True\" \/>\r\n<\/form>\r\n<\/body>\r\n<\/html><\/pre>\n

\u7136\u540e\u6dfb\u52a0\u521b\u5efa XML DataSet \u7684\u811a\u672c\uff0c\u5e76\u4e14\u7ed1\u5b9a XML DataSet \u4e2d\u7684\u503c\u5230 RadioButtonList \u63a7\u4ef6\uff1a<\/p>\n

\r\n<%@ Import Namespace=\"System.Data\" %>\r\n<script runat=\"server\">\r\nsub Page_Load\r\nif Not Page.IsPostBack then   \r\ndim mycountries=New DataSet   \r\nmycountries.ReadXml(MapPath(\"countries.xml\"))   \r\nrb.DataSource=mycountries   \r\nrb.DataValueField=\"value\"   \r\nrb.DataTextField=\"text\"   \r\nrb.DataBind()\r\nend if\r\nend sub\r\n<\/script>\r\n<html>\r\n<body>\r\n<form runat=\"server\">\r\n<asp:RadioButtonList id=\"rb\" runat=\"server\"\r\nAutoPostBack=\"True\" onSelectedIndexChanged=\"displayMessage\" \/>\r\n<\/form>\r\n<\/body>\r\n<\/html><\/pre>\n

\u7136\u540e\u6211\u4eec\u6dfb\u52a0\u4e00\u4e2a\u5b50\u4f8b\u7a0b\uff0c\u5f53\u7528\u6237\u70b9\u51fb RadioButtonList \u63a7\u4ef6\u4e2d\u7684\u67d0\u4e2a\u9879\u76ee\u65f6\uff0c\u8be5\u5b50\u4f8b\u7a0b\u4f1a\u88ab\u6267\u884c\u3002\u5f53\u67d0\u4e2a\u5355\u9009\u6309\u94ae\u88ab\u70b9\u51fb\u65f6\uff0clabel \u4e2d\u4f1a\u51fa\u73b0\u4e00\u884c\u6587\u672c\uff1a<\/p>\n

\u5b9e\u4f8b<\/p>\n

\r\n<%@ Import Namespace=\"System.Data\" %>\r\n<script runat=\"server\">\r\nsub Page_Load\r\nif Not Page.IsPostBack then\r\ndim mycountries=New DataSet\r\nmycountries.ReadXml(MapPath(\"countries.xml\"))\r\nrb.DataSource=mycountries\r\nrb.DataValueField=\"value\"\r\nrb.DataTextField=\"text\"\r\nrb.DataBind()\r\nend if\r\nend sub\r\nsub displayMessage(s as Object,e As EventArgs)\r\nlbl1.text=\"Your favorite country is: \" & rb.SelectedItem.Text\r\nend sub\r\n<\/script>\r\n<html>\r\n<body>\r\n<form runat=\"server\">\r\n<asp:RadioButtonList id=\"rb\" runat=\"server\"\r\nAutoPostBack=\"True\" onSelectedIndexChanged=\"displayMessage\" \/>\r\n<p><asp:label id=\"lbl1\" runat=\"server\" \/><\/p>\r\n<\/form>\r\n<\/body>\r\n<\/html>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u8fd9\u91cc\u6709\u4e00\u4e2a\u540d\u4e3a “countries.xml” \u7684 XML \u6587\u4ef6\uff1a <?xml version=”1.0 […]<\/p>\n","protected":false},"author":1470,"featured_media":243260,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-243258","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/243258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=243258"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/243258\/revisions"}],"predecessor-version":[{"id":243263,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/243258\/revisions\/243263"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/243260"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=243258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=243258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=243258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}