﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-liangchao</title><link>http://www.cnitblog.com/liangchao/</link><description /><language>zh-cn</language><lastBuildDate>Wed, 29 Apr 2026 14:22:13 GMT</lastBuildDate><pubDate>Wed, 29 Apr 2026 14:22:13 GMT</pubDate><ttl>60</ttl><item><title>利用Repeater解决DataGrid的嵌套显示问题</title><link>http://www.cnitblog.com/liangchao/archive/2006/08/14/15212.html</link><dc:creator>BEYOND</dc:creator><author>BEYOND</author><pubDate>Mon, 14 Aug 2006 00:53:00 GMT</pubDate><guid>http://www.cnitblog.com/liangchao/archive/2006/08/14/15212.html</guid><wfw:comment>http://www.cnitblog.com/liangchao/comments/15212.html</wfw:comment><comments>http://www.cnitblog.com/liangchao/archive/2006/08/14/15212.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/liangchao/comments/commentRss/15212.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/liangchao/services/trackbacks/15212.html</trackback:ping><description><![CDATA[
		<p>
				<span id="span_Title"> 一直以来,客户需要在WEB上面显示嵌套的数据页面,如下图所示:<br /><img src="http://www.agilelabs.cn/photos/e5b7a5e4bd9c/images/167/original.aspx" /><br />  而我们的项目全部统一采用DataGrid来进行数据的绑定显示.对于这种嵌套数据的显示,我一直头疼.在网上搜了N种方法:采用嵌套DataGrid...手动在数据绑定的时候进行一些额外操作分割单元格.....全部都麻烦得要死.今天总算在CodeProject上面找到一种方便点的方法:采用Repeater来解决这个问题.<br />    首先,来看下我的DataGrid中列的html代码:</span>
		</p>
		<div>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">asp:BoundColumn </span>
				<span style="COLOR: #ff0000">Visible</span>
				<span style="COLOR: #0000ff">="False"</span>
				<span style="COLOR: #ff0000">DataField</span>
				<span style="COLOR: #0000ff">="ID"</span>
				<span style="COLOR: #0000ff">&gt;&lt;/</span>
				<span style="COLOR: #800000">asp:BoundColumn</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">asp:BoundColumn </span>
				<span style="COLOR: #ff0000">DataField</span>
				<span style="COLOR: #0000ff">="OrganName"</span>
				<span style="COLOR: #ff0000">HeaderText</span>
				<span style="COLOR: #0000ff">="部门名称"</span>
				<span style="COLOR: #0000ff">&gt;&lt;/</span>
				<span style="COLOR: #800000">asp:BoundColumn</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">asp:TemplateColumn </span>
				<span style="COLOR: #ff0000">HeaderText</span>
				<span style="COLOR: #0000ff">="员工"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">ItemTemplate</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">FONT </span>
				<span style="COLOR: #ff0000">face</span>
				<span style="COLOR: #0000ff">="宋体"</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />            </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">asp:Repeater </span>
				<span style="COLOR: #ff0000">id</span>
				<span style="COLOR: #0000ff">="Repeater1"</span>
				<span style="COLOR: #ff0000">runat</span>
				<span style="COLOR: #0000ff">="server"</span>
				<span style="COLOR: #ff0000">DataSource</span>
				<span style="COLOR: #0000ff">='&lt;%# </span>
				<span style="COLOR: #ff0000">((System.Data.DataRowView)Container.DataItem).Row.GetChildRows("parentchild") %</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">'&gt;<br />                </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">HeaderTemplate</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />                    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">table</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />                </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">HeaderTemplate</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />                </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">ItemTemplate</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />                    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">tr</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />                        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">td</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">&lt;%</span>
				<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5"># DataBinder.</span>
				<span style="COLOR: #0000ff; BACKGROUND-COLOR: #f5f5f5">Eval</span>
				<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">(Container.DataItem,</span>
				<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</span>
				<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">[\</span>
				<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</span>
				<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">EmployeeName</span>
				<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">\</span>
				<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</span>
				<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">]</span>
				<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">"</span>
				<span style="COLOR: #000000; BACKGROUND-COLOR: #f5f5f5">)</span>
				<span style="COLOR: #000000; BACKGROUND-COLOR: #ffff00">%&gt;</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">td</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />                    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">tr</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />                </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">ItemTemplate</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />                </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">FooterTemplate</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />                    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">table</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />                </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">FooterTemplate</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />            </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">asp:Repeater</span>
				<span style="COLOR: #0000ff">&gt;&lt;/</span>
				<span style="COLOR: #800000">FONT</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">ItemTemplate</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">asp:TemplateColumn</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<br />其中的ID列表示机构的ID,用来和员工信息中的机构ID进行"关联".<br /><br /><br />再来看关键代码<br /><span style="COLOR: #000000">                DataSet ds </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"></span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> DataSet();<br /><br />                DataTable dtOrgan </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"></span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> DataTable();<br />                dtOrgan.Columns.Add(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ID</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">typeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">));<br />                dtOrgan.Columns.Add(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">OrganName</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">typeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">));<br />                ...<br />                </span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">...往机构表中灌数据...</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br />                ds.Tables.Add(dtOrgan);<br /><br />                DataTable dtEmployee </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"></span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> DataTable();<br />                dtEmployee.Columns.Add(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">OrganID</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">typeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">));<br />                dtEmployee.Columns.Add(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">EmployeeName</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">typeof</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">));<br />                ...<br />                </span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">...往员工表中灌数据...</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br /><br />                ds.Tables.Add(dtEmployee);<br />                ds.Relations.Add(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">parentchild</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,ds.Tables[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">].Columns[</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ID</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">],ds.Tables[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">].Columns[</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">OrganID</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">]);<br />                dgList.DataSource </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> ds.Tables[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">].DefaultView;<br />                dgList.DataBind();<br /><br />最主要的就是利用了DataSet的Relations的属性,通过属性来将父子表关联起来,然后进行数据的绑定.最后,在WEB上运行出来的效果如下所示:<br /><img src="http://www.agilelabs.cn/photos/e5b7a5e4bd9c/images/166/original.aspx" /></span></div>
<img src ="http://www.cnitblog.com/liangchao/aggbug/15212.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/liangchao/" target="_blank">BEYOND</a> 2006-08-14 08:53 <a href="http://www.cnitblog.com/liangchao/archive/2006/08/14/15212.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何提高数据库性能，减少数据库服务器压力瓶颈一两个小方法</title><link>http://www.cnitblog.com/liangchao/archive/2006/07/31/14482.html</link><dc:creator>BEYOND</dc:creator><author>BEYOND</author><pubDate>Mon, 31 Jul 2006 05:48:00 GMT</pubDate><guid>http://www.cnitblog.com/liangchao/archive/2006/07/31/14482.html</guid><wfw:comment>http://www.cnitblog.com/liangchao/comments/14482.html</wfw:comment><comments>http://www.cnitblog.com/liangchao/archive/2006/07/31/14482.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/liangchao/comments/commentRss/14482.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/liangchao/services/trackbacks/14482.html</trackback:ping><description><![CDATA[树立的观念：一个SQL语句，如果在压力测试时CPU占有率达到100%，此语句肯定存在问题。
<p>    在大多数程序员的心里，一直认为数据库加索引，在查询中使用索引，就可以提高数据库性能。其实这种观点有一点的局限性，如果不好好的利用已经建立好的数据库索引，有时反倒给数据库增加更大的处理压力。现在我们举例说明一下：</p><p>    在现有的个人信息管理系统登录处的查询中，有这么一个SQL语句：</p><p>     Select StudentInfoID, StudentNumber, StudentName,UnifyExamInfoID,NetSchoolID from StudentInfo </p><p>     where StudentCrtificateNumber ='130425831217494' and rtrim(ltrim(StudentNumber)) = 'D0462382001'</p><p>     此SQL语句的目的是查找这个考生是否存在，验证登录的效果，就是这么一个简单的SQL语句，在压力测试时，10个用户同时登录，就会造成数据库服务器（2CPU，4G内存，IBM专用服务器）CPU占有率达到100%。而这张表也建立了StudentCrtificateNumber 和 StudentNumber 两个字段的索引， 问题出在哪呢？原因如下：</p><p>     （1）在studentinfo表中，建立了一个索引LX_STUDENTINFO，包括了四个字段，顺序为：studycenternumber,studentnumber,studentname,studentcrtificatenumber。</p><p>    （2）程序员理解的是，这个索引中包括了这两个字段，那么查询时就应该很快。实际不是。</p><p>    大家注意一点，这个LX_STUDENTINFO索引，是四个索引字段，而他们的顺序studycenternumber,studentnumber,studentname,studentcrtificatenumber，在数据库设计中，如果查询采用的第一个字段和第二个字段组合，则该索引有效；如果查询采用第一个、第二个和第三个字段组合，该索引也有效；而如果第一个和第三个，或第四个组合，则该索引是无效的，等同的效果仍是在没有索引的数据库中进行查询。也就是说建立的索引中的字段，在查询使用时，不能隔字段使用。</p><p>    另外，索引中涉及到字段的顺序也会影响查询的性能，如果一个索引包含两个字段A1和A2，那么在查询时，一定要严格按索引中这两个字段的顺序设计查询，比如：select * from a where A1='A' and A2='B'。而如果程序员写成了select * from a where A2='B' and A1='A'的话，虽然不影响程序正常使用，但会增加数据库的压力，并且查询效能会降低。</p><p>    根据这种思路，重新调整了一下这个表的索引，在这个表中增加了一个新的索引，只包括这两个字段，并且按StudentCrtificateNumber 和StudentNumber先后顺序排序。经过300人同时登录的压力测试，CPU占有率才只占2-3%，证明调整结果有效。</p><img src ="http://www.cnitblog.com/liangchao/aggbug/14482.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/liangchao/" target="_blank">BEYOND</a> 2006-07-31 13:48 <a href="http://www.cnitblog.com/liangchao/archive/2006/07/31/14482.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL查询优化--索引</title><link>http://www.cnitblog.com/liangchao/archive/2006/07/26/14242.html</link><dc:creator>BEYOND</dc:creator><author>BEYOND</author><pubDate>Wed, 26 Jul 2006 09:26:00 GMT</pubDate><guid>http://www.cnitblog.com/liangchao/archive/2006/07/26/14242.html</guid><wfw:comment>http://www.cnitblog.com/liangchao/comments/14242.html</wfw:comment><comments>http://www.cnitblog.com/liangchao/archive/2006/07/26/14242.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/liangchao/comments/commentRss/14242.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/liangchao/services/trackbacks/14242.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: sql Server 				索引优化																												 												聚集索引				 , 				表中存储的数据按照索引的顺序存储				 , 				检索效率比普通索引高				 , 				但对数据新增				 / 				修改				 / 				删除的...&nbsp;&nbsp;<a href='http://www.cnitblog.com/liangchao/archive/2006/07/26/14242.html'>阅读全文</a><img src ="http://www.cnitblog.com/liangchao/aggbug/14242.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/liangchao/" target="_blank">BEYOND</a> 2006-07-26 17:26 <a href="http://www.cnitblog.com/liangchao/archive/2006/07/26/14242.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>