{"id":8815,"date":"2014-02-09T04:58:44","date_gmt":"2014-02-08T20:58:44","guid":{"rendered":"http:\/\/bohu.net\/blog\/?p=8815"},"modified":"2014-02-09T04:58:44","modified_gmt":"2014-02-08T20:58:44","slug":"c%e4%b8%ad%e7%94%a8%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e5%8f%96%e9%a1%b5%e9%9d%a2%e4%b8%8b%e6%8b%89%e8%8f%9c%e5%8d%95select%e4%b8%ad%e7%9a%84%e5%80%bc","status":"publish","type":"post","link":"https:\/\/www.bohu.net\/blog\/8815\/","title":{"rendered":"C#\u4e2d\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u53d6\u9875\u9762\u4e0b\u62c9\u83dc\u5355(select)\u4e2d\u7684\u503c"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>\u7ed9\u51e0\u4e2a\u5728C#\u4e2d\uff0c\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u53d6\u9875\u9762\u4e0b\u62c9\u83dc\u5355(select)\u4e2d\u7684\u503c\u793a\u4f8b:<\/p>\n<pre class=\"brush:csharp\">\/\/\u53d6html\u4e2d\u5168\u90e8 select \u7684 name\nRegex reg_name = new Regex(@\"(?&lt;=&lt;select name=\\\"\").*?(?=\\\"\")\");\n\n\/\/\u53d6html\u4e2d\u5168\u90e8&lt;select&gt;\u9879\u7684\u503c\nRegex reg_select = new Regex(\"(?is)&lt;select name=*.*?&gt;]*.*?&lt;\/select&gt;\");\n\n\/\/\u53d6html\u4e2d\u4e00\u4e2a select name \u7b49\u4e8e\"Status\"\u7684\u503c\nRegex status = new Regex(@\"(?is)&lt;select name=\\\"\"status\\\"\"&gt;]*.*?&lt;\/select&gt;\");<\/pre>\n<p>&nbsp;<\/p>\n<p>\u4e00\u4e0b\u662f\u4e00\u6bb5\u5b8c\u6574\u7684\u4ee3\u7801\u548c\u65b9\u6cd5\uff0c\u53d6html\u4e2d\u4e00\u4e2a\u4e0b\u62c9\u83dc\u5355 select name \u7b49\u4e8e&#8221;Status&#8221;\u7684\u4e2d\u503c\uff0c\u6dfb\u52a0\u5230DropDownList\u4e2d:<\/p>\n<pre class=\"brush:csharp\">        string strDoc = \uff08\u4f60\u7684html\uff09;\n\n        \/\/\u53d6html\u4e2d\u4e00\u4e2a\u4e0b\u62c9\u83dc\u5355 select name \u7b49\u4e8e\"Status\"\u7684\u4e2d\u503c\n        Regex status = new Regex(@\"(?is)&lt;select name=\\\"\"status\\\"\"&gt;]*.*?&lt;\/select&gt;\");\n        MatchCollection mc_status = status.Matches(strDoc);\n        getSelectOptions(mc_status, cmbStatus);\n\n        \/\/\/ &lt;summary&gt;\n        \/\/\/ \u53d6select\u5bf9\u5217\u8868\u590d\u5236\n        \/\/\/ &lt;\/summary&gt;\n        \/\/\/ &lt;param name=\"selected\"&gt;&lt;\/param&gt;\n        \/\/\/ &lt;param name=\"cmb\"&gt;&lt;\/param&gt;\n        void getSelectOptions(MatchCollection selected, ComboBox cmb)\n        {\n            if (selected.Count &lt; 1)\n                return;\n            txtValues.Text = \"\";\n            txtValues.Text = selected[0].Value.Replace(\"&lt;\/option&gt;\", Environment.NewLine);\n            string tmpTxt = \"\";\n            foreach (string s in txtValues.Lines)\n            {\n                if (s == \"\")\n                    continue;\n                string a = \"\";\n                a = s.Replace(\"\\\"\", \"\").Replace(\"&lt;option value=\\\"\", \"\");\n                int x = a.LastIndexOf(\"&gt;\");\n                tmpTxt += a.Substring(x + 1) + Environment.NewLine;\n            }\n            txtValues.Text = tmpTxt.Trim();\n            cmb.Items.Clear();\n            cmb.Items.AddRange(txtValues.Lines);\n            cmb.SelectedIndex = 0;\n            cmb.Size = cmb.PreferredSize;\n        }<\/pre>\n<p>&nbsp;<\/p>\n<p><strong><a title=\"Permalink to \u63a8\u8350\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u6d4b\u8bd5\/\u9a8c\u8bc1\u5de5\u5177\" href=\"http:\/\/bohu.net\/blog\/8814\" rel=\"bookmark\">\u63a8\u8350\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u6d4b\u8bd5\/\u9a8c\u8bc1\u5de5\u5177<\/a><\/strong>\u00a0&#8211; <a href=\"http:\/\/bohu.net\/blog\/8814\">http:\/\/bohu.net\/blog\/8814<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u7ed9\u51e0\u4e2a\u5728C#\u4e2d\uff0c\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u53d6\u9875\u9762\u4e0b\u62c9\u83dc\u5355(select)\u4e2d\u7684\u503c\u793a\u4f8b: \/\/\u53d6html\u4e2d\u5168\u90e8  &hellip; <a href=\"https:\/\/www.bohu.net\/blog\/8815\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cC#\u4e2d\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u53d6\u9875\u9762\u4e0b\u62c9\u83dc\u5355(select)\u4e2d\u7684\u503c\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4,42,26],"tags":[98,135,279,336,425,448],"class_list":["post-8815","post","type-post","status-publish","format-standard","hentry","category-net","category-c-net","category-winform-","category-26","tag-c","tag-dropdownlist","tag-option","tag-select","tag-winform","tag-448"],"_links":{"self":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/8815","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/comments?post=8815"}],"version-history":[{"count":0,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/posts\/8815\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/media?parent=8815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/categories?post=8815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bohu.net\/blog\/wp-json\/wp\/v2\/tags?post=8815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}