﻿<?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>BlogJava-&lt;DIV id="ddm_Title"&gt;&lt;H1&gt;大大毛&amp;nbsp;&lt;i class="little"&gt;的笔记&lt;/i&gt;&lt;/H1&gt;&lt;H2&gt;&amp;nbsp&amp;nbsp;DDM's Note&lt;/H2&gt;&lt;/DIV&gt;-文章分类-&lt;b value="0202" class="ddm_subItem"&gt;ASP.NET&lt;/b&gt;</title><link>http://www.blogjava.net/tw-ddm/category/13837.html</link><description>&lt;div id="ddm_subTitle"&gt;
&lt;h2 class="catchline"&gt;
        哪怕没有办法一定有说法,&lt;br/&gt;
        就算没有鸽子一定有乌鸦,&lt;br/&gt;
        固执无罪&amp;nbsp;梦想有价,&lt;br/&gt;
        让他们惊讶.
&lt;/h2&gt;
&lt;/div&gt;</description><language>zh-cn</language><lastBuildDate>Wed, 28 Feb 2007 22:56:43 GMT</lastBuildDate><pubDate>Wed, 28 Feb 2007 22:56:43 GMT</pubDate><ttl>60</ttl><item><title>GridView在DataTable空行时不显示的处理</title><link>http://www.blogjava.net/tw-ddm/articles/71625.html</link><dc:creator>大大毛</dc:creator><author>大大毛</author><pubDate>Sun, 24 Sep 2006 18:00:00 GMT</pubDate><guid>http://www.blogjava.net/tw-ddm/articles/71625.html</guid><wfw:comment>http://www.blogjava.net/tw-ddm/comments/71625.html</wfw:comment><comments>http://www.blogjava.net/tw-ddm/articles/71625.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/tw-ddm/comments/commentRss/71625.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/tw-ddm/services/trackbacks/71625.html</trackback:ping><description><![CDATA[
		<font size="2">
				<br />   <strong>问题：</strong><br /><br />      GridView控件应用很是广泛，通常将它与DataSourceControl搭配使用，当然也可以手工指定DataSource属性来完成数据绑定。如果<strong>数据源返回一个空行的数据集</strong>(例如查询不到指定记录等)时，将会出现两种情况：<br />      1.当GridView未指定&lt;EmptyDataTemplate&gt;或EmptyDataText属性时，控件将不会被最终生成，网页上的表现为空白，这样不仅感觉不爽，而且很容易造成布局的变形。<br />      2.如果指定了&lt;EmptyDataTemplate&gt;或EmptyDataText属性，网页上将最终产生一个table元素，它具有一行一格，可以显示出设置的提示信息，但是这种情况下该table将不会显示出表头来。<br />      通常希望的是，即使数据源返回一个空行的数据集，但是原有的Table元素也应该被显示出来，它应该带一个表头行，以及一个空白行。<br /><br /><br />   <strong>解决办法：</strong><br /><br />      通过手工向数据源添加一个新行即可解决。在此过程应该处理好以下几个方面的事情。<br />      1.在 New 一行时，如果包含主键列，则该列的值会被自动赋值(如 int 列会被赋值 0 )。对此应该手工将新行的每一列都赋值为 DBNull.Value ；<br />      2.由于可能存在有非空约束，会造成插入失败，因此必须手工将每一列的 AllowDBNull 属性重新设定<br />      以下示例 GridView 绑定至 ObjectDataSource 时的处理代码：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id="Code_Closed_Image_000234" onclick="this.style.display='none'; Code_Closed_Text_000234.style.display='none'; Code_Open_Image_000234.style.display='inline'; Code_Open_Text_000234.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" /><img id="Code_Open_Image_000234" style="DISPLAY: none" onclick="this.style.display='none'; Code_Open_Text_000234.style.display='none'; Code_Closed_Image_000234.style.display='inline'; Code_Closed_Text_000234.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" /><span id="Code_Closed_Text_000234" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><strong>Selected事件</strong></span><span id="Code_Open_Text_000234" style="DISPLAY: none"><br /><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> ObjectDataSource2_Selected(</span><span style="COLOR: #0000ff">object</span><span style="COLOR: #000000"> sender, ObjectDataSourceStatusEventArgs e) {<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">转型到DataTable</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        DataTable table </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (DataTable)e.ReturnValue;<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">如果返回的是张空表</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (table.Rows.Count </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">) {<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">生成DataRow对象</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            DataRow row </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> table.NewRow();<br /><br />            </span><span style="COLOR: #0000ff">foreach</span><span style="COLOR: #000000"> (DataColumn col </span><span style="COLOR: #0000ff">in</span><span style="COLOR: #000000"> table.Columns) {<br />                </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">重新设置AllowDBNull属性</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">                col.AllowDBNull </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br />                </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">显式赋值成null</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">                row[col] </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> DBNull.Value;<br />            }<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">将DataRow对象添加至table中</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            table.Rows.Add(row);<br />        }<br /><br />    }</span></span></div><br />      效果示意如下：<br /><table cellspacing="0" cellpadding="0" width="300" border="1"><tbody><tr><th>标题1</th><th>标题2</th><th>标题...</th></tr><tr><td> </td><td> </td><td> </td></tr></tbody></table><br />      就此来说效果并不是十分理想，如果能够实现以下的效果那就更好了： <br /><table cellspacing="0" cellpadding="0" width="300" border="1"><tbody><tr><th>标题1</th><th>标题2</th><th>标题...</th></tr><tr><td align="middle" colspan="3"><font color="red" size="2">没有查找到符合条件的记录</font></td></tr></tbody></table><p><br />      为达成目的，还需要在 GridView 中加一点小改进，处理一下那个空行。<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id="Code_Closed_Image_014310" onclick="this.style.display='none'; Code_Closed_Text_014310.style.display='none'; Code_Open_Image_014310.style.display='inline'; Code_Open_Text_014310.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" /><img id="Code_Open_Image_014310" style="DISPLAY: none" onclick="this.style.display='none'; Code_Open_Text_014310.style.display='none'; Code_Closed_Image_014310.style.display='inline'; Code_Closed_Text_014310.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" /><span id="Code_Closed_Text_014310" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><strong>DataBound事件</strong></span><span id="Code_Open_Text_014310" style="DISPLAY: none"><br /><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> GridView1_DataBound(</span><span style="COLOR: #0000ff">object</span><span style="COLOR: #000000"> sender, EventArgs e) {<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">如果是空行,判断条件为:行数=1且主键列=DBNull.Value,如果需要区分是初始化/提交状态,可以加入 Page.IsPostBack 判断</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (GridView1.DataKeys.Count </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">&amp;&amp;</span><span style="COLOR: #000000"> GridView1.DataKeys[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">].Values[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">] </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> DBNull.Value) {<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">清除掉该空行的全部单元格</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            GridView1.Rows[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">].Cells.Clear();<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">新建单元格对象</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            TableCell cell </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> TableCell();<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">合并单元格</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            cell.ColumnSpan </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> GridView1.Columns.Count;<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">GridView1.EmptyDataText已经设置为  "没有查找到符合条件的记录"<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">设置单元格内容为GridView1.EmptyDataText,把提示文本给分离出来</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            cell.Text </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> GridView1.EmptyDataText;<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">向空行中加入单元格</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            GridView1.Rows[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">].Cells.Add(cell);<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">让该行应用EmptyDataRowStyle样式,这样可以更加灵活,比如可以很容易的应用主题</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            GridView1.Rows[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">].ApplyStyle(GridView1.EmptyDataRowStyle);<br />        }<br />        <br />    }</span></span></div><p>      如此一来，配合 GridView 的 EmptyDataText , EmptyDataRowStyle 即可以实现令人满意的效果，见下图。<br /><br />            <img height="65" alt="GridView空数据集效果图" src="http://www.blogjava.net/images/blogjava_net/tw-ddm/10051/r_emptyDataSet.PNG" width="423" border="0" /><br /><br /></p></font>
<img src ="http://www.blogjava.net/tw-ddm/aggbug/71625.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/tw-ddm/" target="_blank">大大毛</a> 2006-09-25 02:00 <a href="http://www.blogjava.net/tw-ddm/articles/71625.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>数据控件</title><link>http://www.blogjava.net/tw-ddm/articles/65343.html</link><dc:creator>大大毛</dc:creator><author>大大毛</author><pubDate>Wed, 23 Aug 2006 10:52:00 GMT</pubDate><guid>http://www.blogjava.net/tw-ddm/articles/65343.html</guid><wfw:comment>http://www.blogjava.net/tw-ddm/comments/65343.html</wfw:comment><comments>http://www.blogjava.net/tw-ddm/articles/65343.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/tw-ddm/comments/commentRss/65343.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/tw-ddm/services/trackbacks/65343.html</trackback:ping><description><![CDATA[
		<p>
				<font face="Verdana" size="2">   <strong>Repeater控件</strong>，共有五个模板，编辑该控件的模板只能在ASP源码中进行<br />      1.ItemTemplate，正常显示项，如果定义了交替项模板，则仅代表奇数Item(从1开始算)<br />      2.AlternatingItemTemplate，交替项，代表偶数Item<br />      3.HeaderTemplate，页眉，在控件的最前<br />      4.FooterTemplate，页脚，在控件的最后<br />      5.SeparatorTemplate，分隔项，位于各Item之间，如使用&lt;br/&gt;实现各项换行<br />   适用于：<br />      替代<strong>只读</strong>显示容器内容的循环，如将一个ResultSet显示成一张表。<br />      HeaderTemplate中使用&lt;table&gt;&lt;tr&gt;，ItemTemplate/AlternatingItemTemplate中使用&lt;td&gt;&lt;/td&gt;，SeparatorTemplate中使用&lt;/tr&gt;&lt;tr&gt;，FooterTemplate中使用&lt;/tr&gt;&lt;/table&gt;可以实现一个 &lt;table&gt; 元素效果。<br /><br />   <strong>DataList控件，</strong>共有七个模板<br />      6.SelectedItemTemplate，选择项<br />      7.EditItemTemplate，编辑项<br />   适用于：<br />      <strong>可编辑数据</strong>的显示，因此在普通的DataSource指定后2006年8月24日，需要绑定数据源的主键列(指定控件的<strong>DataKeyField</strong>属性)。<br />      该控件提供了多种事件，由放在Item中的Button控件激发。<br />      Button控件将会激发ItemCommand事件，可通过传入的事件参数来引发其它事件，例如使用SelectedItem模板：<br /></font>
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Verdana">
								<span style="COLOR: #000000">    </span>
								<span style="COLOR: #0000ff">protected</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">void</span>
								<span style="COLOR: #000000"> DataList1_ItemCommand(</span>
								<span style="COLOR: #0000ff">object</span>
						</font>
				</font>
				<font size="2">
						<font face="Verdana">
								<span style="COLOR: #000000"> source, DataListCommandEventArgs e) {<br />        </span>
								<span style="COLOR: #0000ff">if</span>
								<span style="COLOR: #000000"> (e.CommandName </span>
								<span style="COLOR: #000000">==</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">Select</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">) {                          </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">判断激发事件的Button.CommandName</span>
						</font>
				</font>
				<span style="COLOR: #008000">
						<br />
				</span>
				<font size="2">
						<font face="Verdana">
								<span style="COLOR: #000000">            </span>
								<span style="COLOR: #0000ff">this</span>
								<span style="COLOR: #000000">.DataList1.SelectedIndex </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> e.Item.ItemIndex;  </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">让激发事件的行被选中</span>
						</font>
				</font>
				<span style="COLOR: #008000">
						<br />
				</span>
				<font size="2">
						<font face="Verdana">
								<span style="COLOR: #000000">            myDataBind();                                                </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">这里需要进行重新绑定</span>
						</font>
				</font>
				<span style="COLOR: #008000">
						<br />
				</span>
				<font size="2">
						<font face="Verdana">
								<span style="COLOR: #000000">        }<br />    }</span>
						</font>
				</font>
		</div>
		<p>
				<font face="Verdana" size="2">      使用EditItemTemplate模板，将Button.CommandName指定成"edit"即可。</font>
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Verdana">
								<span style="COLOR: #000000">    </span>
								<span style="COLOR: #0000ff">protected</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">void</span>
								<span style="COLOR: #000000"> DataList1_EditCommand(</span>
								<span style="COLOR: #0000ff">object</span>
						</font>
				</font>
				<font size="2">
						<font face="Verdana">
								<span style="COLOR: #000000"> source, DataListCommandEventArgs e) {<br />        </span>
								<span style="COLOR: #0000ff">this</span>
								<span style="COLOR: #000000">.DataList1.SelectedIndex </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">-</span>
								<span style="COLOR: #000000">1</span>
								<span style="COLOR: #000000">;                       </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">放弃选择</span>
						</font>
				</font>
				<span style="COLOR: #008000">
						<br />
				</span>
				<font size="2">
						<font face="Verdana">
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">this</span>
								<span style="COLOR: #000000">.DataList1.EditItemIndex </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> e.Item.ItemIndex;    </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">让当前行进入编辑状态</span>
						</font>
				</font>
				<span style="COLOR: #008000">
						<br />
				</span>
				<font size="2">
						<font face="Verdana">
								<span style="COLOR: #000000">        myDataBind();<br />    }</span>
						</font>
				</font>
		</div>
		<p>
				<font face="Verdana" size="2">      在EditItemTemplate模板中可以将允许修改的列绑定到子控件上，并放入两个Button，CommandName分别指定为"update","cancel"与DataList的事件相对应，再在对应的数据更新/放弃事件中编程即可。</font>
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font face="Verdana" size="2">
						<img id="Code_Closed_Image_161412" onclick="this.style.display='none'; Code_Closed_Text_161412.style.display='none'; Code_Open_Image_161412.style.display='inline'; Code_Open_Text_161412.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" />
						<img id="Code_Open_Image_161412" style="DISPLAY: none" onclick="this.style.display='none'; Code_Open_Text_161412.style.display='none'; Code_Closed_Image_161412.style.display='inline'; Code_Closed_Text_161412.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" />
						<span id="Code_Closed_Text_161412" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">Cancel事件</span>
				</font>
				<span id="Code_Open_Text_161412" style="DISPLAY: none">
						<br />
						<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000">    </span>
										<span style="COLOR: #0000ff">protected</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">void</span>
										<span style="COLOR: #000000"> DataList1_CancelCommand(</span>
										<span style="COLOR: #0000ff">object</span>
								</font>
						</font>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000"> source, DataListCommandEventArgs e) {<br />        </span>
										<span style="COLOR: #0000ff">this</span>
										<span style="COLOR: #000000">.DataList1.EditItemIndex </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">;  </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">放弃编辑状态</span>
								</font>
						</font>
						<span style="COLOR: #008000">
								<br />
						</span>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000">        myDataBind();<br />    }</span>
								</font>
						</font>
				</span>
		</div>
		<br />
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font face="Verdana" size="2">
						<img id="Code_Closed_Image_161318" onclick="this.style.display='none'; Code_Closed_Text_161318.style.display='none'; Code_Open_Image_161318.style.display='inline'; Code_Open_Text_161318.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" />
						<img id="Code_Open_Image_161318" style="DISPLAY: none" onclick="this.style.display='none'; Code_Open_Text_161318.style.display='none'; Code_Closed_Image_161318.style.display='inline'; Code_Closed_Text_161318.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" />
						<span id="Code_Closed_Text_161318" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">Update事件</span>
				</font>
				<span id="Code_Open_Text_161318" style="DISPLAY: none">
						<br />
						<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000">    </span>
										<span style="COLOR: #0000ff">protected</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">void</span>
										<span style="COLOR: #000000"> DataList1_UpdateCommand(</span>
										<span style="COLOR: #0000ff">object</span>
								</font>
						</font>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000"> source, DataListCommandEventArgs e) {<br /><br />        </span>
										<span style="COLOR: #0000ff">string</span>
										<span style="COLOR: #000000"> id </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">this</span>
										<span style="COLOR: #000000">.DataList1.DataKeys[e.Item.ItemIndex].ToString();       </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">获取编辑行所对应的主键</span>
								</font>
						</font>
						<span style="COLOR: #008000">
								<br />
						</span>
						<span style="COLOR: #000000">
								<br />
								<br />
								<font face="Verdana" size="2">        SqlConnection con </font>
						</span>
						<font face="Verdana" size="2">
								<span style="COLOR: #000000">=</span>
						</font>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000"> Db.getConnection();<br />        </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">根据主键更新数据库</span>
								</font>
						</font>
						<span style="COLOR: #008000">
								<br />
						</span>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000">        SqlCommand cmd </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">new</span>
										<span style="COLOR: #000000"> SqlCommand(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">update vote set topic=@topic where vID=@vID</span>
										<span style="COLOR: #000000">"</span>
								</font>
						</font>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000">, con);<br />        SqlParameter p1 </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">new</span>
										<span style="COLOR: #000000"> SqlParameter(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">@topic</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">, SqlDbType.VarChar, </span>
										<span style="COLOR: #000000">20</span>
								</font>
						</font>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000">);<br />        p1.Value </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> ((TextBox)e.Item.FindControl(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">txtTopic</span>
										<span style="COLOR: #000000">"</span>
								</font>
						</font>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000">)).Text.Trim();<br />        cmd.Parameters.Add(p1);<br />        SqlParameter p2 </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">new</span>
										<span style="COLOR: #000000"> SqlParameter(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">@vID</span>
										<span style="COLOR: #000000">"</span>
								</font>
						</font>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000">, SqlDbType.Int);<br />        p2.Value </span>
										<span style="COLOR: #000000">=</span>
								</font>
						</font>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000"> id;<br />        cmd.Parameters.Add(p2);<br /><br />        con.Open();<br /><br />        cmd.ExecuteNonQuery();<br /><br />        con.Close();<br /><br />        </span>
										<span style="COLOR: #0000ff">this</span>
										<span style="COLOR: #000000">.DataList1.EditItemIndex </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">;  </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">放弃编辑状态</span>
								</font>
						</font>
						<span style="COLOR: #008000">
								<br />
						</span>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000">        myDataBind();<br /><br />    }</span>
								</font>
						</font>
				</span>
		</div>
		<br />
		<font face="Verdana" size="2">      将Button控件的CommandName指定为"delete"，可激发数据删除事件：<br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Verdana">
								<img id="Code_Closed_Image_170953" onclick="this.style.display='none'; Code_Closed_Text_170953.style.display='none'; Code_Open_Image_170953.style.display='inline'; Code_Open_Text_170953.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" />
								<img id="Code_Open_Image_170953" style="DISPLAY: none" onclick="this.style.display='none'; Code_Open_Text_170953.style.display='none'; Code_Closed_Image_170953.style.display='inline'; Code_Closed_Text_170953.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" />
								<span id="Code_Closed_Text_170953" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">Delete事件</span>
						</font>
				</font>
				<span id="Code_Open_Text_170953" style="DISPLAY: none">
						<br />
						<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000">    </span>
										<span style="COLOR: #0000ff">protected</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">void</span>
										<span style="COLOR: #000000"> DataList1_DeleteCommand(</span>
										<span style="COLOR: #0000ff">object</span>
								</font>
						</font>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000"> source, DataListCommandEventArgs e) {<br />        </span>
										<span style="COLOR: #0000ff">string</span>
										<span style="COLOR: #000000"> id </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">this</span>
										<span style="COLOR: #000000">.DataList1.DataKeys[e.Item.ItemIndex].ToString();       </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">获取编辑行所对应的主键</span>
								</font>
						</font>
						<span style="COLOR: #008000">
								<br />
						</span>
						<span style="COLOR: #000000">
								<br />
								<font face="Verdana" size="2">        SqlConnection con </font>
						</span>
						<span style="COLOR: #000000">
								<font face="Verdana" size="2">=</font>
						</span>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000"> Db.getConnection();<br />        </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">根据主键更新数据库</span>
								</font>
						</font>
						<span style="COLOR: #008000">
								<br />
						</span>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000">        SqlCommand cmd </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">new</span>
										<span style="COLOR: #000000"> SqlCommand(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">delete vote where vID=@vID</span>
										<span style="COLOR: #000000">"</span>
								</font>
						</font>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000">, con);<br />        SqlParameter p1 </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">new</span>
										<span style="COLOR: #000000"> SqlParameter(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">@vID</span>
										<span style="COLOR: #000000">"</span>
								</font>
						</font>
						<font size="2">
								<font face="Verdana">
										<span style="COLOR: #000000">, SqlDbType.Int);<br />        p1.Value </span>
										<span style="COLOR: #000000">=</span>
								</font>
						</font>
						<span style="COLOR: #000000">
								<font face="Verdana" size="2"> id;<br />        cmd.Parameters.Add(p1);<br /><br />        con.Open();<br />        cmd.ExecuteNonQuery();<br />        con.Close();<br /><br />        myDataBind();<br />    }<br /></font>
						</span>
				</span>
		</div>
		<p>
				<font face="Verdana" size="2">      通常需要在Update/Delete按钮上加入确认，如果是静态提示可以直接在Button的属性中加入：</font>
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Verdana">
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">asp:Button ID</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">btnDelete</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> runat</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">server</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> CommandName</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">delete</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> Text</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">删除</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> <strong>OnClientClick</strong></span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">
										<font color="#0000ff">return confirm(</font>
										<font color="#ff0000">'delete?'</font>
										<font color="#0000ff">);</font>
								</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">/&gt;</span>
						</font>
				</font>
		</div>
		<font face="Verdana" size="2">      在这里可以看到，是利用了Button控件的 OnClientClick 属性调用本地的 JS函数 confirm() 来实现确认的功能。如果想提示动态消息(如提示一个ID)，偶没有试出来，不过可以写在代码段里，利用ItemCreated事件，这样：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id="Code_Closed_Image_112026" onclick="this.style.display='none'; Code_Closed_Text_112026.style.display='none'; Code_Open_Image_112026.style.display='inline'; Code_Open_Text_112026.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" /><img id="Code_Open_Image_112026" style="DISPLAY: none" onclick="this.style.display='none'; Code_Open_Text_112026.style.display='none'; Code_Closed_Image_112026.style.display='inline'; Code_Closed_Text_112026.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" /><span id="Code_Closed_Text_112026" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">ItemCreated事件</span><span id="Code_Open_Text_112026" style="DISPLAY: none"><br /><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> DataList1_ItemCreated(</span><span style="COLOR: #0000ff">object</span><span style="COLOR: #000000"> sender, DataListItemEventArgs e) {<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">此事件表示的是Item的建立,而在不同的模板中是会有不同的呈现形式的,因此需要对当前的状态进行判断<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">该delete按钮是在正常浏览状态下的,在select/edit状态下并不存在</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (e.Item.ItemType </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> ListItemType.Item </span><span style="COLOR: #000000">||</span><span style="COLOR: #000000"> e.Item.ItemType </span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> ListItemType.AlternatingItem) {<br /><br />            </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> s1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">return confirm('你确认要删除ＩＤ=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />            s1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> s1 </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> DataBinder.Eval(e.Item.DataItem, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">vID</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />            s1 </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> s1 </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">的投票吗？');</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /><br />            ((Button)e.Item.FindControl(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">btnDelete</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)).Attributes.Add(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">onClick</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, s1);<br />        }<br />    }</span></span></div><p>      这样一来就可以在Button激发DataList的事件之前进行简单的确认了，不过需要注意的是：<br />         .用这种方式时，在运行时如果有错误是<strong>不会有什么提示消息</strong>的，而且流程直接向下进行；<br />         .如果同时使用了两种，那么Button上的OnClientClick属性优先。<br /><br />      该控件的显示方式也与Repeater控件大不相同，它的显示方式分为"表"和"流"两种，默认使用表布局。<br />         使用表布局时控件会自动生成一个&lt;table&gt;元素，样式则由各模板对应的&lt;style&gt;指定，在该控件的运用中不应该再使用如Repeater那种自构造&lt;table&gt;元素的方法，因为该控件中经常需要用到FindControls方法，自行加入元素会影响到该方法。<br />      可以看到模板还具有自己所对应的Style，这个样式与当前Item所使用的模块对应，例如选中第1项，如果没有配置&lt;SelectedItemStyle&gt;才会使用&lt;ItemStyle&gt;所定义的样式。<br /><br />   <strong>手工分页：</strong><br />      如上面提到的Repeater、DataList控件都没有提供分页的功能，此时可以对数据源进行分页再配合自定义的导航条来实现分页效果。<br />      手工分页，需要用到 System.Web.UI.WebControls.PagedDataSource 对象。<br />      例如：在页面中加入lblPageNo控件以保存当前页号(text="0")，btnPrevious表示上一页，btnNext表示下一页。</p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id="Code_Closed_Image_000444" onclick="this.style.display='none'; Code_Closed_Text_000444.style.display='none'; Code_Open_Image_000444.style.display='inline'; Code_Open_Text_000444.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" /><img id="Code_Open_Image_000444" style="DISPLAY: none" onclick="this.style.display='none'; Code_Open_Text_000444.style.display='none'; Code_Closed_Image_000444.style.display='inline'; Code_Closed_Text_000444.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" /><span id="Code_Closed_Text_000444" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">新的代码</span><span id="Code_Open_Text_000444" style="DISPLAY: none"><br /><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><img id="Codehighlighter1_4_49_Open_Image" onclick="this.style.display='none'; Codehighlighter1_4_49_Open_Text.style.display='none'; Codehighlighter1_4_49_Closed_Image.style.display='inline'; Codehighlighter1_4_49_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_4_49_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_4_49_Closed_Text.style.display='none'; Codehighlighter1_4_49_Open_Image.style.display='inline'; Codehighlighter1_4_49_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="COLOR: #000000">    </span><span id="Codehighlighter1_4_49_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="Codehighlighter1_4_49_Open_Text"><span style="COLOR: #808080">///</span><span style="COLOR: #008000"> </span><span style="COLOR: #808080">&lt;summary&gt;</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="COLOR: #808080">///</span><span style="COLOR: #008000"> 数据绑定<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    </span><span style="COLOR: #808080">///</span><span style="COLOR: #008000"> </span><span style="COLOR: #808080">&lt;/summary&gt;</span><span style="COLOR: #808080"></span></span><br /><img id="Codehighlighter1_80_1124_Open_Image" onclick="this.style.display='none'; Codehighlighter1_80_1124_Open_Text.style.display='none'; Codehighlighter1_80_1124_Closed_Image.style.display='inline'; Codehighlighter1_80_1124_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_80_1124_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_80_1124_Closed_Text.style.display='none'; Codehighlighter1_80_1124_Open_Image.style.display='inline'; Codehighlighter1_80_1124_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> myDataBind() </span><span id="Codehighlighter1_80_1124_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_80_1124_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        SqlConnection con </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> Db.getConnection();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        SqlDataAdapter sda </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> SqlDataAdapter();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        sda.SelectCommand </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> SqlCommand(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">select * from vote</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,con);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        DataTable table </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> DataTable(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">vote</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        sda.Fill(table);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">使用了分页</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">        PagedDataSource pds </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> PagedDataSource();    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">使用一个PagedDataSource对象</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">        pds.DataSource </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> table.DefaultView;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        pds.PageSize </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">;                               </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">每页3条记录</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">        pds.AllowPaging </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;                         </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">使用分页效果</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> pageNo </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">.Parse(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.lblPageNo.Text);    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">取得保留的当前页码,初始值="0"</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">        pds.CurrentPageIndex </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> pageNo;                  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">设置当前页<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">开关上，下页导航按钮</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.btnPrevious.Enabled </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">(pageNo </span><span style="COLOR: #000000">&lt;=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.btnNext.Enabled </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">(pageNo </span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000"> pds.PageCount </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">将DataList的数据源指向该PagedDataSource</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.DataList1.DataSource </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> pds;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.DataList1.DataBind();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.DataList1.DataKeyField </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">vID</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">指定需要绑定的主键列</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="COLOR: #000000">        DataList1.DataBind();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        con.Close();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">上一页</span><span style="COLOR: #008000"><br /><img id="Codehighlighter1_1203_1315_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1203_1315_Open_Text.style.display='none'; Codehighlighter1_1203_1315_Closed_Image.style.display='inline'; Codehighlighter1_1203_1315_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1203_1315_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1203_1315_Closed_Text.style.display='none'; Codehighlighter1_1203_1315_Open_Image.style.display='inline'; Codehighlighter1_1203_1315_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> tbtnPrevious_Click(</span><span style="COLOR: #0000ff">object</span><span style="COLOR: #000000"> sender, EventArgs e) </span><span id="Codehighlighter1_1203_1315_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_1203_1315_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.lblPageNo.Text </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> Convert.ToString(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">.Parse(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.lblPageNo.Text) </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        myDataBind();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">下一页</span><span style="COLOR: #008000"><br /><img id="Codehighlighter1_1388_1500_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1388_1500_Open_Text.style.display='none'; Codehighlighter1_1388_1500_Closed_Image.style.display='inline'; Codehighlighter1_1388_1500_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1388_1500_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1388_1500_Closed_Text.style.display='none'; Codehighlighter1_1388_1500_Open_Image.style.display='inline'; Codehighlighter1_1388_1500_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> btnNext_Click(</span><span style="COLOR: #0000ff">object</span><span style="COLOR: #000000"> sender, EventArgs e) </span><span id="Codehighlighter1_1388_1500_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_1388_1500_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.lblPageNo.Text </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> Convert.ToString(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">.Parse(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.lblPageNo.Text) </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        myDataBind();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    }</span></span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span></span></div><p>   <strong>排序：</strong><br />      利用数据视图DataView的Sort属性来实现排序，将其属性指定为一个字段名 + 排序规则。<br />      在GridView中列上可以设置SortExpression排序表达式，并在Sorting事件中指定DataView的Sort为该事件的SortExpression即可。<br /><br />   GridView：<br />      就是一个数据表格，在以前的版本中叫DataGrid。它的功能比DataList更为强大，支持数据表格显示、按列的控制(DataList按名字就只支持一列)、列的排序、分页、空页控制等多种功能，可以将DataList看做是一个轻量级的控件，不过从这两种控件的属性及使用方式来看，风格完全不同，这可能也是两控件命名不一的原因吧。<br /><br /><br /><br /> </p></font>
<img src ="http://www.blogjava.net/tw-ddm/aggbug/65343.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/tw-ddm/" target="_blank">大大毛</a> 2006-08-23 18:52 <a href="http://www.blogjava.net/tw-ddm/articles/65343.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>生成随机码检验图片</title><link>http://www.blogjava.net/tw-ddm/articles/64936.html</link><dc:creator>大大毛</dc:creator><author>大大毛</author><pubDate>Mon, 21 Aug 2006 19:00:00 GMT</pubDate><guid>http://www.blogjava.net/tw-ddm/articles/64936.html</guid><wfw:comment>http://www.blogjava.net/tw-ddm/comments/64936.html</wfw:comment><comments>http://www.blogjava.net/tw-ddm/articles/64936.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/tw-ddm/comments/commentRss/64936.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/tw-ddm/services/trackbacks/64936.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 网页中需要用到这样的功能，参照网上的介绍，做了一个放在这里备查。   效果图：										   为了方便调用，写成了一个类(RandomCodeImage.cs)。												using				 System;				using				 System.Drawing;				/**/										///						 ...&nbsp;&nbsp;<a href='http://www.blogjava.net/tw-ddm/articles/64936.html'>阅读全文</a><img src ="http://www.blogjava.net/tw-ddm/aggbug/64936.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/tw-ddm/" target="_blank">大大毛</a> 2006-08-22 03:00 <a href="http://www.blogjava.net/tw-ddm/articles/64936.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>实现单选/多选动态转化</title><link>http://www.blogjava.net/tw-ddm/articles/64088.html</link><dc:creator>大大毛</dc:creator><author>大大毛</author><pubDate>Thu, 17 Aug 2006 04:15:00 GMT</pubDate><guid>http://www.blogjava.net/tw-ddm/articles/64088.html</guid><wfw:comment>http://www.blogjava.net/tw-ddm/comments/64088.html</wfw:comment><comments>http://www.blogjava.net/tw-ddm/articles/64088.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/tw-ddm/comments/commentRss/64088.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/tw-ddm/services/trackbacks/64088.html</trackback:ping><description><![CDATA[
		<font size="2">
				<br />   <strong>问题：</strong><br />   页面中会遇到实现单选/多选的方法，不幸的是选择单选或多选是动态决定的，例如实现投票，需要从vote表中取出数据，从而决定当前的投票是多选还是单选。<br />   实现这种功能最简单的方法就是放上两个panel容器，一个放checkboxlist，一个放radiobuttonlist，根据检索到的数据实现开关显示。<br /><br />   <strong>解决方法：</strong><br />   使用System.Web.UI.WebControls.ListControl可以轻松的实现动态的定制。<br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<span style="COLOR: #0000ff">protected</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> Page_Load(</span>
						<span style="COLOR: #0000ff">object</span>
				</font>
				<font size="2">
						<span style="COLOR: #000000"> sender, EventArgs e) {<br />  </span>
						<span style="COLOR: #0000ff">bool</span>
						<span style="COLOR: #000000"> isSingle </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">false</span>
				</font>
				<font size="2">
						<span style="COLOR: #000000">;<br />  System.Web.UI.WebControls.ListControl list </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">null</span>
				</font>
				<font size="2">
						<span style="COLOR: #000000">;<br />  </span>
						<span style="COLOR: #0000ff">if</span>
				</font>
				<font size="2">
						<span style="COLOR: #000000">(isSingle) {<br />    list </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
				</font>
				<font size="2">
						<span style="COLOR: #000000"> RadioButtonList();<br />  } </span>
						<span style="COLOR: #0000ff">else</span>
				</font>
				<font size="2">
						<span style="COLOR: #000000"> {<br />    list </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
				</font>
				<font size="2">
						<span style="COLOR: #000000"> CheckBoxList();<br />  }<br />  </span>
						<span style="COLOR: #0000ff">this</span>
				</font>
				<font size="2">
						<span style="COLOR: #000000">.Panel1.Controls.Add(list);<br /><br />  </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000">(</span>
						<span style="COLOR: #000000">!</span>
				</font>
				<font size="2">
						<span style="COLOR: #000000">IsPostBack()) {<br />    rebindData(list);<br />  }<br />}<br /><br /></span>
						<span style="COLOR: #0000ff">private</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">void</span>
				</font>
				<font size="2">
						<span style="COLOR: #000000"> rebindData(ListControl ctl) {<br />  ctl.Items.Add(</span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> ListItem(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">文本</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">值</span>
						<span style="COLOR: #000000">"</span>
				</font>
				<font size="2">
						<span style="COLOR: #000000">);<br />  </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">
								<img src="http://www.blogjava.net/images/dot.gif" />或者在这里进行数据绑定ctl.DataSource<img src="http://www.blogjava.net/images/dot.gif" />.</span>
				</font>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">
						<font size="2">}</font>
				</span>
		</div>
		<br />
		<font size="2">   <strong>后记：</strong><br />   ASP.NET中规定服务端控件必须放置在Form runat="server"之内，因此动态添加时，this.Controls.Add(new Control())是不可以的，必须放入容器中，例如上面的Panel或者页面的Form中this.form1.Controls.Add...。</font>
<img src ="http://www.blogjava.net/tw-ddm/aggbug/64088.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/tw-ddm/" target="_blank">大大毛</a> 2006-08-17 12:15 <a href="http://www.blogjava.net/tw-ddm/articles/64088.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ASP.NET学习笔记--02</title><link>http://www.blogjava.net/tw-ddm/articles/62259.html</link><dc:creator>大大毛</dc:creator><author>大大毛</author><pubDate>Mon, 07 Aug 2006 16:04:00 GMT</pubDate><guid>http://www.blogjava.net/tw-ddm/articles/62259.html</guid><wfw:comment>http://www.blogjava.net/tw-ddm/comments/62259.html</wfw:comment><comments>http://www.blogjava.net/tw-ddm/articles/62259.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/tw-ddm/comments/commentRss/62259.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/tw-ddm/services/trackbacks/62259.html</trackback:ping><description><![CDATA[
		<font face="Verdana">
				<p>
						<br />
						<font size="2">   <strong>ASP.NET提供的WEB控件分类</strong><br />      内部控件，基于HTML控件，具有 runas=server 的属性；<br />      列表控件，用于在WEB页中创建数据列表，常用的有 Repeater, DataList, DataGrid<br />      复杂控件，用简单控件聚合而成，如日历<br />      验证控件，对输入数据进行准确性和范围的检查(验证工作在 Server 端进行)<br /><br /><br />   <strong>文本输入</strong><br />      <strong>textbox</strong><br />      通过设置该控件的 TextMode 属性可以实现 1.单行文本 2.多行文本 3.密码文本 三种VIEW，多行文本模式时属性 cols,rows生效。<br /><br />   </font>
						<font size="2">
								<strong>控制转移<br /></strong>      1.<strong>Button</strong><br />      2.<strong>LinkButton</strong><br />      3.<strong>ImageButton</strong><br />      4.</font>
						<font size="2">
								<strong>HyperLink<br /></strong>      1 - 3 都属于 button ，可以响应事件，而 HyperLink 则不行。HyperLink 与 HTML 中的锚一样，点击它并不会产生向服务器的提交，而将在客户端完成跳转，与锚标记相比的好处在于，它属于服务器控件，因此可以在类中使用 this 指针加以引用，方便编程。<br />      Button 有个 commandName 属性，在演示中让它充当了 TAG 的角色，用于一个事件响应多个 Button 控件时对对象的区别：<br />         if( ((System.Web.UI.WebControls.Button)sender).CommandName == "b1" )<br />      LinkButton，样子与 HyperLink差不多，但是有着明显的区别，它是可以响应事件的(会产生对服务器的提交)；<br />      ImageButton，具有一个ImageURL属性可以加载图片，AlternateText属性指定图片无法找到时显示的文字，另外它的事件响应形参类型也有着不同，是 ImageClickEventArgs 类型，该类型具有的 x,y属性可以使事件对于点击到图片上的具体区域做出反应。</font>
				</p>
				<p>
						<font size="2">   <strong>选择</strong><br />      1.<strong>CheckBox</strong><br />      2.<strong>RadioButton</strong><br />      3.<strong>ListBox</strong><br />      4.</font>
						<font size="2">
								<strong>DropDownList<br /></strong>      CheckBox，复选框，属性 Checked 表示该复选框是否被选中，另外还提供一个 CheckBoxList 作为一个集合控件方便操作；<br />      RadioButton，单选框，属性 Checked 表示该单选框是否被选中，通过设定多个 RadioButton 属性 GroupName 为相同值，可以很方便的将多个控件组合成一个Group，另外还提供一个集合控件 RadioButtonList<br />      有很多控件都具有一个 AutoPostBack 属性，该属性表示是否响应服务器事件，如果为false则不会响应事件，而为true时一旦触发事件就会向服务器提交，因此需要避免控件经常性的向服务端提交。<br /><br />   <strong>容器</strong><br />      Panel，面板。通常用于在同一页中实现切换(轮流显示)。<br /><br />   <strong>复杂控件</strong><br />      1.ADRotator，广告控件。AdvertisementFile 属性可以为控件指定一个XML配置文件，KeywordFilter 属性能够根据配置文件中各广告的 key 进行筛选。<br />      该广告控件<strong>一次只能显示一张</strong>图片，只有当刷新页面或重连时会选取其它的图片，相同于ASP中用的那个随机图片<br />      配置文件，一个&lt;AD&gt;标签代表一个广告。</font>
				</p>
				<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
						<font size="2">
								<img id="Code_Closed_Image_002242" onclick="this.style.display='none'; Code_Closed_Text_002242.style.display='none'; Code_Open_Image_002242.style.display='inline'; Code_Open_Text_002242.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" />
								<img id="Code_Open_Image_002242" style="DISPLAY: none" onclick="this.style.display='none'; Code_Open_Text_002242.style.display='none'; Code_Closed_Image_002242.style.display='inline'; Code_Closed_Text_002242.style.display='inline';" height="16" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" />
								<span id="Code_Closed_Text_002242" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<strong>XML配置文件</strong>
								</span>
						</font>
						<span id="Code_Open_Text_002242" style="DISPLAY: none">
								<br />
								<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
								<font size="2">
										<span style="COLOR: #0000ff">&lt;</span>
										<span style="COLOR: #800000">Advertisements</span>
										<span style="COLOR: #0000ff">&gt;</span>
								</font>
								<span style="COLOR: #000000">
										<br />
										<font size="2">    </font>
								</span>
								<font size="2">
										<span style="COLOR: #0000ff">&lt;</span>
										<span style="COLOR: #800000">Ad</span>
										<span style="COLOR: #0000ff">&gt;</span>
								</font>
								<span style="COLOR: #000000">
										<br />
										<font size="2">        </font>
								</span>
								<font size="2">
										<span style="COLOR: #0000ff">&lt;</span>
										<span style="COLOR: #800000">ImageUrl</span>
										<span style="COLOR: #0000ff">&gt;</span>
										<span style="COLOR: #000000">图像文件的位置</span>
										<span style="COLOR: #0000ff">&lt;/</span>
										<span style="COLOR: #800000">ImageUrl</span>
										<span style="COLOR: #0000ff">&gt;</span>
								</font>
								<span style="COLOR: #000000">
										<br />
										<font size="2">        </font>
								</span>
								<font size="2">
										<span style="COLOR: #0000ff">&lt;</span>
										<span style="COLOR: #800000">NavigateUrl</span>
										<span style="COLOR: #0000ff">&gt;</span>
										<span style="COLOR: #000000">单击广告后跳到的URL</span>
										<span style="COLOR: #0000ff">&lt;/</span>
										<span style="COLOR: #800000">NavigateUrl</span>
										<span style="COLOR: #0000ff">&gt;</span>
								</font>
								<span style="COLOR: #000000">
										<br />
										<font size="2">        </font>
								</span>
								<font size="2">
										<span style="COLOR: #0000ff">&lt;</span>
										<span style="COLOR: #800000">AlternateText</span>
										<span style="COLOR: #0000ff">&gt;</span>
										<span style="COLOR: #000000">鼠标在图像上显示的文本</span>
										<span style="COLOR: #0000ff">&lt;/</span>
										<span style="COLOR: #800000">AlternateText</span>
										<span style="COLOR: #0000ff">&gt;</span>
								</font>
								<span style="COLOR: #000000">
										<br />
										<font size="2">        </font>
								</span>
								<font size="2">
										<span style="COLOR: #0000ff">&lt;</span>
										<span style="COLOR: #800000">Keyword</span>
										<span style="COLOR: #0000ff">&gt;</span>
										<span style="COLOR: #000000">指定类别</span>
										<span style="COLOR: #0000ff">&lt;/</span>
										<span style="COLOR: #800000">Keyword</span>
										<span style="COLOR: #0000ff">&gt;</span>
								</font>
								<span style="COLOR: #000000">
										<br />
										<font size="2">        </font>
								</span>
								<font size="2">
										<span style="COLOR: #0000ff">&lt;</span>
										<span style="COLOR: #800000">Impressions</span>
										<span style="COLOR: #0000ff">&gt;</span>
										<span style="COLOR: #000000">广告出现的优先级,越大越优先</span>
										<span style="COLOR: #0000ff">&lt;/</span>
										<span style="COLOR: #800000">Impressions</span>
										<span style="COLOR: #0000ff">&gt;</span>
								</font>
								<span style="COLOR: #000000">
										<br />
										<font size="2">    </font>
								</span>
								<font size="2">
										<span style="COLOR: #0000ff">&lt;/</span>
										<span style="COLOR: #800000">Ad</span>
										<span style="COLOR: #0000ff">&gt;</span>
								</font>
								<span style="COLOR: #000000">
										<br />
								</span>
								<font size="2">
										<span style="COLOR: #0000ff">&lt;/</span>
										<span style="COLOR: #800000">Advertisements</span>
										<span style="COLOR: #0000ff">&gt;</span>
								</font>
						</span>
				</div>
				<p>
						<font size="2">      2.Calendar，日历控件。<br /><br />   <strong>上传控件</strong><br />      FileUpload，文件上传。PostedFile 属性表示已经上传的文件对象，可以通过该对象的属性及方法获取上传文件的各种属性。FileName 属性表示上传文件的文件名(PostedFile对象也具有一个FileName属性，但是表示的是上传文件的全路径名，需要手工提取文件名)。PostedFile.SaveAs(path) 方法可以将上传的文件保存在服务端的指定路径下，注意这里的 path 必须是一个绝对地址，因此使用时需要进行相对路径--&gt;绝对路径的转换，可以使用 Server.MapPath(path) 方法。<br /><br />   <strong>验证控件</strong><br />      1.RequiredFieldValidator，空值验证；<br />      2.CompareValidator，比较验证。该控件有三种工作方式<br />         .值比较，ValueToCompare 属性用于设定特征值，Type 指定特征值的类型，Operator 属性指定比较运算符 (Value Operator Control.value)；<br />         .类型检验，Type 指定类型，Operator 属性使用 "DataTypeCheck"；<br />         .控件比较，Type，Operator，ControlToValidate，ControlToCompare属性即可。<br />      3.RangeValidator，值域验证；<br />      4.RegularExpressionValidator，正则表达式验证；<br />      5.CustomValidator，自定义验证。它支持客户端及服务端自定义验证，Server 端验证时该控件提供一个ServerValidate事件，该事件的ServerValidateEventArgs对象类型参数的 Value 属性表示该控件绑定的被验证控件的 Value，IsValid 属性表示是否通过验证，只需在事件中根据自定义的规则设置 IsValid属性即可；<br />      6.ValidationSummary，列举页面中的全部验证错误信息。用于将错误信息集中显示。<br />      在页面中使用验证控件时，除了第1种，2-4都不会对空值进行验证，因此需要根据情况搭配使用。<br />      缺省情况下，有些验证需要在 server 端进行(如CustomValidator)，流程会成为 先提交后验证，这时在编程时就需要用到 <strong>Page.IsValid</strong> 属性，只有当该属性为true时才表示通过了全部的验证。<br />      对于IE的低版本来说，客户端验证会出现问题，此时可以强行指定全部使用服务端验证&lt;%@ page ClientTarget="DownLevel" %&gt;<br />      在页面中常常包含大量的验证控件，在使用时常常需要根据需要使一组验证生效。此时验证控件的 ValidationGroup 属性就可以派上用场，该属性可以对验证控件进行分组，同时在使用时在能够引起提交的控件上指定ValidationGroup属性(该属性同样会影响到Page.IsValid的结果)。当然如果在页面上使用了ValidationSummary控件的话，也需要指定该属性，不然它不会显示对应组控件的错误提示信息。<br /></font>
				</p>
		</font>
<img src ="http://www.blogjava.net/tw-ddm/aggbug/62259.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/tw-ddm/" target="_blank">大大毛</a> 2006-08-08 00:04 <a href="http://www.blogjava.net/tw-ddm/articles/62259.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ASP.NET学习笔记--01</title><link>http://www.blogjava.net/tw-ddm/articles/62213.html</link><dc:creator>大大毛</dc:creator><author>大大毛</author><pubDate>Mon, 07 Aug 2006 09:51:00 GMT</pubDate><guid>http://www.blogjava.net/tw-ddm/articles/62213.html</guid><wfw:comment>http://www.blogjava.net/tw-ddm/comments/62213.html</wfw:comment><comments>http://www.blogjava.net/tw-ddm/articles/62213.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/tw-ddm/comments/commentRss/62213.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/tw-ddm/services/trackbacks/62213.html</trackback:ping><description><![CDATA[
		<br />
		<font face="Verdana" size="2">   刚刚开始学习ASP.NET，环境：XP,VS2005,SQLServer2000，学习资料：北大青鸟的视频教程<br /><br />   <strong>ASP.NET与ASP的区别</strong><br />      asp.net 运行于 .net 框架之上，经过了伪编译，而 asp 则是直接运行在IIS上的，在调用时由DLL进行解释；<br />      asp.net 支持三种开发语言：vb.net,c#,j#，而 asp 仅支持 vbscript 的语法；<br />      asp.net 提供了控件支持，而 asp 则没有；<br />      asp.net 支持OOP，代码也是按类来组织的，asp 只能依靠精巧的代码实现；<br />      asp.net 在页面的处理上采用了VB的事件驱动，大大简化了开发难度，asp 依靠的是手工驱动；<br />      asp.net 提供的VIEWSTATE机制，使得页面元素可以保持原有的值，asp 必须依靠手工代码；<br />      asp.net 使用了代码分离，asp 则没有，现在老板就能看清楚你写的那堆垃圾在哪儿了；<br />      asp.net 的IDE功能上强大许多，不过在HTML元素的设计上成了一只鸡肋，许多地方俺还是习惯手工改写；<br /><br />   <strong>ASP.NET提供的控件</strong><br />      提供的常用控件都在VS工具箱的"标准"及"HTML"栏中，所谓标准控件就是指服务器控件，一拖出来就有个 runas="server" 的属性，当然HTML控件也可以加上这个属性变身为服务器控件，一旦拥有这个runas那么该控件就会成为类的一项属性，在类成员中使用this指针就可以直接引用，果然是方便快捷。不过界面元素的动作也相应着发生了变化，如果是普通的HTML元素，那么响应它事件的只能是本地 script 代码，而一旦成为服务器控件，那么所有针对它的事件响应都会在服务器端完成。<br /><br />   <strong>常用的事件：</strong><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Page_Load(</span><span style="COLOR: #0000ff">object</span><span style="COLOR: #000000"> sender, EventArgs e) {<br />}</span></div>      这个事件最为常用，在设计器中双击页面就会切到该事件方法中来。该事件发生在页面每次被装载时，不过这里的Load跟本地App的Load不一样，由于HTTP的特性决定了客户/服务端的联接不可能是持续和双向的。因此客户端浏览器每发一次请求，服务端就会Load页面一次。<br />      这个事件通常配合 Page.IsPostBack 属性使用，该属性在Load完成之后才会被设为 true 值，因此只有第一次的Load，该属性值才为 false，看教程中的示例，需要初始化环境时，需要将初始化代码置入 if(!Page.IsPostBack) 块中。<br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Page_Init(</span><span style="COLOR: #0000ff">object</span><span style="COLOR: #000000"> sender, EventArgs e) {<br />}</span></div>      Page_Init 事件在 Load 事件之前发生，页面在加载时的顺序是 控件Init(),页面Init(),页面Load(),控件Load()<br /><br /><br />   <strong>ASP.NET从提交的数据中取值</strong><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">1</span>  <span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> userName </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> Request[</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">userName</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">].ToString();<br /><br /></span><span style="COLOR: #008080">2</span>  <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> userName </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> Request.Form.Get(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">userName</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /><br /></span><span style="COLOR: #008080">3</span>  <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000"> userName </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> Request.QueryString[</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">userName</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">];</span></div><p>      取值的方法与 asp 相同。<br />      第1行方法适用于 Post/Get 两种提交方式；第2行只能用于 Post 提交，这里使用了集合的Get方法；第3行只能用于 Get 提交，这里使用另外一种获取集合成员的方法。<br /><br />   <strong>ASP.NET查询MsSQL数据库</strong><br />      需要引用的命名空间(相当于JAVA中的包):System.Data.SqlClient;<br />      步骤:<br />         1.新建一个 SqlConnection 连接对象，并打开；<br />            new SqlConnection("server=服务的地址;database=数据库名;uid=sa;pwd=")；<br />            con.Open();<br />         2.新建一个 SqlCommand 命令对象；<br />            new SqlCommand(SQL语句,con);<br />         3.通过调用 SqlCommand 对象的方法获得数据。<br />            例如：<br />            SqlDataReader sdr = cmd.ExecuteReader();   //获得一个只向前的游标<br />            while(sdr.Read()) {<br />               ...<br />            }<br />         4.释放资源<br />            使用 using 语句，属于 .net 的专有语法了，在块的结束将由 using 语法调用 IDisposable 接口定义的 Dispose()方法。因此包含在 using 语句内的对象都应该实现 IDisposable 接口。<br />            使用 finally ，这个方法还是比较容易接受一些，try/catch/finally组合除了可以释放资源外还可以捕获异常。<br />         查了一下资料，MS将连接池也傻瓜了一把(只有使用System.Data.SqlClient包时)，除非在 SqlConnection 对象的连接字串中显式指定，否则自动配置连接池。因此在 SqlConnection 对象的使用上应该做到随手关闭的好习惯，呵。</p></font>
<img src ="http://www.blogjava.net/tw-ddm/aggbug/62213.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/tw-ddm/" target="_blank">大大毛</a> 2006-08-07 17:51 <a href="http://www.blogjava.net/tw-ddm/articles/62213.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>