易截截图软件、单文件、免安装、纯绿色、仅160KB

Asp.net数据绑定

数据绑定以及Container.DataItem的具体分析
灵活的运用数据绑定操作
绑定到简单属性:<%#UserName%>
绑定到集合:<asp:ListBox id="ListBox1" datasource='<%# myArray%>' runat="server">
绑定到表达式:<%#(class1.property1.ToString() + "," + class1.property2.ToString())%>
绑定到方法返回值:<%# GetSafestring(str) %>
绑定到Hashtable:<%# ((DictionaryEntry)Container.DataItem).Key%>
绑定到ArrayList:<%#Container.DataItem %>
若数组里里放的是对象则可能要进行必要的转换后再绑定如:
<%#((对象类型)Container.DataItem).属性%>
绑定到DataView,DataTable,DataSet:
<%#((DataRowView)Container.DataItem)["字段名"]%>或
<%#((DataRowView)Container.DataItem).Rows[0]["字段名"]%>
要格式化则:
<%#string.Format("格式",((DataRowView)Container.DataItem)["字段名"])%>
<%#DataBinder.Eval(Container.DataItem,"字段名","格式")%>
绑定到DataReader:
<%#((IDataReader)Container.DataItem).字段名%>
当然为了方便一般使用最多的就是DataBinder类的Eval方法了.不过这样对于同时要绑定大量的数据效率要低一些
在绑定数据时经常会用到这个句程序:<%# DataBinder.Eval(Container.DataItem,"xxxx")%>或者<%# DataBinder.Eval(Container,"DataItem.xxxx")%>
今天又学到一种,而且微软也说这种方法的效率要比以上两种高。
<%# ((DataRowView)Container.DataItem)["xxxx"]%>
很有用的,这样可以在前台页面做好多事情了。
还要记住要这样用必须要在前台页面导入名称空间System.Data,否则会生成错误信息。
<%@ Import namespace="System.Data" %>
这种用法其实和<%# ((DictionaryEntry)Container.DataItem).Key%>是一个道理。
绑定到DataSet、DataTable时:
<%#((System.Data.DataRowView)Container.DataItem)["字段名"]%>
<%#((System.Data.DataRowView)Container.DataItem)[索引]%>
绑定到DataReader时:
<%#((System.Data.Common.DbDataRecord)Container.DataItem)[索引]%>
<%#((System.Data.Common.DbDataRecord)Container.DataItem)["字段名"]%>
关键是Container这个东西,它比较神秘。它的名称空间是System.ComponentModel。对于它我还需要进一步理解。
初学.NET,现在


相关文档:

PHP与ASP.NET比较的浅析 南三方


 
PHP与ASP.NET比较的各个方面是什么呢?PHP与ASP.NET比较的必要性是什么呢?那么本文就给你一个答案。
PHP与ASP.NET比较的前言,不管你是不是已经选择了PHP,根据它在如下表格中在价格、速度、效率、安全性、平台支持性和开源与否上的表现,我们都能判断出它的强项是远胜于弱点的。唯一不足的是缺少面向对象的支 ......

ASP.net 4.0 针对SEO的改进

搜索引擎优化对任何面向公众的网站来说都非常重要,ASP.net 4.0 为此就做了大量改造。这些改进包括如下:
301
永久性重定向
随着时间的迁移,网站的一些页面地址会发生变化,这会导致搜索引擎收录的链接地址、用户收藏的地址失
效。Response.Redirect() 就是解决这个问题的。但是Response.Redirect 有以下问题:
Respo ......

asp.net准确截取文本长度(取得标题的字符数)

asp.net中自带的CutString只能截取字符数量的长度,但中英文字符数有差异,一个中文字等同于二个英文字符的宽度,这样对截取后的效果不理想.使用以下的方法就能解决.
//调用方法
string title=BLL.CutStr.CutString("标题",10);using System;
using System.Collections.Generic;
using System.Text;
namespace BLL
{
&n ......

asp.net将sql数据导出excel表格(代sql字段名)

protected void Button1_Click(object sender, EventArgs e)
{
string strsql = "select * from TreeViewTemp where parentID=0";
DataTable dt = db.GetDataTable(strsql);
StringWriter sw = new StringWriter();
//StreamWriter sw = new Strea ......

asp.net将页面中gridview中的数据导入excel表中

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
namespace ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号