1.C#è¯è¨åççµåç¸åç³»ç»
2.在datalist 中,控件控件删除checkbox选中的同行数据(asp.net)
3.Evalï¼ï¼åBindï¼ï¼çåºå«
4.å
³äº.netä¸çrepeater
5.asp.net2005 自定义控件拖动不了
C#è¯è¨åççµåç¸åç³»ç»
é¦å éè¦å¨å级ç®å½ä¸å»ºç«æ件夹FileSystem
//åå°ä»£ç :
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebShop
{
/// <summary>
/// filesystem çæè¦è¯´æã
/// </summary>
public class filesystem : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.DataList DataList1;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.HtmlControls.HtmlInputFile fileFeild1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
Bind();
}
}
private void Bind()
{
string initpath="";
if(Request["path"]==null)
{
initpath=Server.MapPath("FileSystem");
}
else
{
initpath=Request["path"];
}
this.Label1.Text=initpath;
DataTable dt=new DataTable();
DataColumn dc0=new DataColumn("Image",System.Type.GetType("System.String"));
dt.Columns.Add(dc0);
DataColumn dc1=new DataColumn("Name",System.Type.GetType("System.String"));
dt.Columns.Add(dc1);
DirectoryInfo di=new DirectoryInfo(this.Label1.Text);
DirectoryInfo[] dis=di.GetDirectories();
foreach(DirectoryInfo d in dis)
{
DataRow dr=dt.NewRow();
dr[0]="<a href='filesystem.aspx?path="+HttpUtility.UrlEncode(d.FullName,System.Text.Encoding.UTF8)+"'><img src='images/folder.gif' border=0/></a>";
dr[1]=d.Name;
dt.Rows.Add(dr);
}
FileInfo[] fis=di.GetFiles();
foreach(FileInfo f in fis)
{
string ex=f.Extension.ToLower();
if(ex==".jpg" || ex==".jpeg" || ex==".gif" || ex==".png" || ex==".bmp")
{
string fullname=f.FullName;
string urlpath=fullname.Substring(fullname.IndexOf("FileSystem"));
string url=HttpUtility.UrlEncode(urlpath,System.Text.Encoding.UTF8);
DataRow dr=dt.NewRow();
dr[0]="<a href='"+url+"' target='_blank'><img src='"+url+"' border=0 width= height=/></a>";
dr[1]=f.Name;
dt.Rows.Add(dr);
}
}
this.DataList1.DataSource=dt;
this.DataList1.DataBind();
}
#region Web çªä½è®¾è®¡å¨çæç代ç
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该è°ç¨æ¯ ASP.NET Web çªä½è®¾è®¡å¨æå¿ éçã
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计å¨æ¯ææéçæ¹æ³ - ä¸è¦ä½¿ç¨ä»£ç ç¼è¾å¨ä¿®æ¹
/// æ¤æ¹æ³çå 容ã
/// </summary>
private void InitializeComponent()
{
this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void LinkButton1_Click(object sender, System.EventArgs e)
{
string Parent=Directory.GetParent(this.Label1.Text).ToString();
if(Parent.IndexOf("FileSystem")>-1)
{
Response.Redirect("filesystem.aspx?path="+Parent);
}
else
{
return;
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
HttpPostedFile hpf=this.fileFeild1.PostedFile;
string ClientPath=hpf.FileName;
string filename=Path.GetFileName(ClientPath);
string ex=Path.GetExtension(filename);
if(ex==".jpg" || ex==".jpeg" || ex==".gif" || ex==".png" || ex==".bmp")
{
string SavePath=this.Label1.Text+"\\"+filename;
hpf.SaveAs(SavePath);
Bind();
}
else
{
Response.Write(Tools.GetAlertJS("æä¸ä¼ çå¾çæ ¼å¼ä¸æ£ç¡®ï¼"));
return;
}
}
private void Button2_Click(object sender, System.EventArgs e)
{
string filename=this.TextBox1.Text;
Directory.CreateDirectory(this.Label1.Text+"\\"+filename);
Bind();
}
private void Button3_Click(object sender, System.EventArgs e)
{
for(int i=0;i<this.DataList1.Items.Count;i++)
{
if(((CheckBox)this.DataList1.Items[i].FindControl("CheckBox1")).Checked)
{
int index=this.DataList1.Items[i].ItemIndex;
string filePath=this.Label1.Text+"\\"+this.DataList1.DataKeys[index].ToString();
if(Directory.Exists(filePath))
{
Directory.Delete(filePath,true);
}
if(File.Exists(filePath))
{
File.Delete(filePath);
}
Bind();
}
}
}
}
}
åå°é¡µé¢:
<%@ Page language="c#" Codebehind="filesystem.aspx.cs" AutoEventWireup="false" Inherits="WebShop.filesystem" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>filesystem</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="/intellisense/ie5" name="vs_targetSchema">
<LINK href="CssStyle.css" type="text/css" rel="stylesheet">
<form id="Form1" method="post" runat="server">
</HEAD>
<body MS_POSITIONING="GridLayout">
<FONT face="å®ä½">
<table cellSpacing="1" cellPadding="0" width="" align="center" bgColor="#" border="0">
<tr>
<td bgColor="#c" colSpan="3"><IMG src="images/FileSystemBaner.gif"></td>
</tr>
<tr>
<td width="" bgColor="#e3e3e3" rowSpan="2">
<asp:linkbutton id="LinkButton1" runat="server">åé</asp:linkbutton></td>
<td width="" bgColor="#efefef" colSpan="2">
<asp:datalist id="DataList1" runat="server" RepeatColumns="4" RepeatDirection="Horizontal" DataKeyField="Name"
Width="">
<ItemTemplate>
<table width="" align="center">
<tr>
<td align="center" width=""></td>
<td align="left" width=""><%#DataBinder.Eval(Container.DataItem,"Image")%>
</td>
</tr>
<tr>
<td width="" align="right">
<asp:CheckBox ID="checkBox1" Runat="server" /></td>
<td width="" align="left"><font face="å®ä½"><%#DataBinder.Eval(Container.DataItem,"Name")%></font></td>
</tr>
</table>
</ItemTemplate>
</asp:datalist></td>
</tr>
<tr>
<td align="right" bgColor="#efefef" colSpan="2"><asp:button id="Button3" runat="server" Text="å é¤éä¸é¡¹"></asp:button>
<input id="fileFeild1" type="file" name="fileFeild1" runat="server">
<asp:button id="Button1" runat="server" Text="ç¡®å®ä¸ä¼ "></asp:button><br>
<asp:textbox id="TextBox1" runat="server"></asp:textbox>
<asp:button id="Button2" runat="server" Text="å建ç®å½"></asp:button></td>
</tr>
<tr>
<td bgColor="#" colSpan="3"><span class="STYLE1"><asp:label id="Label2" runat="server" ForeColor="White"> å½åæå¨ä½ç½®ï¼</asp:label><SPAN class="STYLE1"><asp:label id="Label1" runat="server" ForeColor="White" Width="px"></asp:label></SPAN></span></td>
</tr>
</table>
</FONT></FORM>
</body>
</HTML>
在datalist 中,删除checkbox选中的同行数据(asp.net)
写一个方法,通过foreach来循环得到选中的checkbox,在checkbox上绑定ID <asp:CheckBox ID="ChkBox" ToolTip='<%#Eval("id")%>' runat="server" />
foreach (Datalist item in this.datalist.Items)
{
CheckBox chkItem = (CheckBox)item.FindControl("ChkBox");
if (chkItem.Checked)
{
//被勾选
ids += chkItem.ToolTip + ",";
}
}
if (ids != "")
{
ids = ids.Substring(0, ids.Length - 1);
}
return ids;
然后后面删除时间的时候调用这个方法,只需要在SQL语句中 delete from table where id 这里用in就可以了(方法名)
Evalï¼ï¼åBindï¼ï¼çåºå«
Eval(
"
")åBind(
"
")ãè¿ä¸¤ç§ä¸ä¸ªååç»å®ï¼ä¸ä¸ªååç»å®
bindæ¯ååç»å®,ä½éæ°æ®æºå¯æ´æ¹æè½ç¨
ASP.NET
2.0æ¹åäºæ¨¡æ¿ä¸çæ°æ®ç»å®æä½ï¼æv1.xä¸çæ°æ®ç»å®è¯æ³DataBinder.Eval(Container.DataItem,
fieldname)ç®å为Eval(fieldname)ãEvalæ¹æ³ä¸DataBinder.Evalä¸æ ·å¯ä»¥æ¥åä¸ä¸ªå¯éçæ ¼å¼åå符串åæ°ã缩ççEvalè¯æ³ä¸DataBinder.Evalçä¸åç¹å¨äºï¼Evalä¼æ ¹æ®æè¿ç容å¨å¯¹è±¡ï¼ä¾å¦DataListItemï¼çDataItemå±æ§æ¥èªå¨å°è§£æå段ï¼èDataBinder.Evaléè¦ä½¿ç¨åæ°æ¥æå®å®¹å¨ãç±äºè¿ä¸ªåå ï¼Evalåªè½å¨æ°æ®ç»å®æ§ä»¶ç模æ¿ä¸ä½¿ç¨ï¼èä¸è½ç¨äºPageï¼é¡µé¢ï¼å±ãå½ç¶ï¼ASP.NET
2.0页é¢ä¸ä»ç¶æ¯æDataBinder.Evalï¼ä½ å¯ä»¥å¨ä¸æ¯æç®åçEvalè¯æ³çç¯å¢ä¸ä½¿ç¨å®ã
ä¸é¢çä¾åæ¼ç¤ºäºå¦ä½ä½¿ç¨æ°çç®åçEvalæ°æ®ç»å®è¯æ³ç»å®å°DataListæ°æ®é¡¹æ¨¡æ¿ï¼ItemTemplateï¼ä¸çImageãLabelåHyperLinkæ§ä»¶ã
ï¼asp:DataList
ID=
"DataList1
"
RepeatColumns=
"5
"
Width=
"
"
runat=
"server
"
DataSourceID=
"ObjectDataSource1
"ï¼
ãï¼ItemTemplateï¼
ããï¼asp:HyperLink
ID=
"HyperLink1
"
runat=
"server
"
NavigateUrl=
'ï¼%#
Eval(
"PhotoID
",
"PhotoFormViewPlain.aspx?ID={ 0}
")
%ï¼
'ï¼
ããï¼asp:Image
ID=
"Image1
"
Runat=
"server
"
ImageUrl=
'ï¼%#
Eval(
"FileName
",
"images/thumbs/{ 0}
")
%ï¼
'
/ï¼ï¼/asp:HyperLinkï¼
ããï¼asp:Label
ID=
"CaptionLabel
"
runat=
"server
"
Text=
'ï¼%#
Eval(
"Caption
")
%ï¼
'
/ï¼
ãï¼/ItemTemplateï¼
ï¼/asp:DataListï¼ï¼br
/ï¼
ï¼asp:ObjectDataSource
ID=
"ObjectDataSource1
"
runat=
"server
"
TypeName=
"DataComponentTableAdapters.PhotosTableAdapter
"
SelectMethod=
"GetPhotosForAlbum
"ï¼
ããæ°æ®ç»å®ä¹å¯ä»¥ä½ä¸ºæ§ä»¶ç主é¢å®ä¹ï¼theme
definitionï¼çä¸é¨åï¼è¿æ ·æ们就å¯ä»¥éè¿æ¹å主é¢æ¥éæå°æ¹å模æ¿åæ§ä»¶çå¸å±åå¤è§ãä½æ¯Themeï¼ä¸»é¢ï¼æ¨¡æ¿ä¸åªè½ä½¿ç¨Evalï¼æè åé¢è®¨è®ºçBindï¼ãç»å®å°ä»»æçç¨æ·ä»£ç æ¯è¢«ç¦æ¢çã
--------å ³æ³¨ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
常è§ç»å®æ ¼å¼ï¼ä¸è¿ä»ä»¬çæ§è½æåºå«ã
<%#
DataBinder.Eval(Container.DataItem,
"[n]")
%>
<%#
DataBinder.Eval(Container.DataItem,
"ColumnName")
%>
<%#
DataBinder.Eval(Container.DataItem,
"ColumnName",
null)
%>
<%#
DataBinder.Eval(Container,
"DataItem.ColumnName",
null)
%>
<%#
((DataRowView)Container.DataItem)["ColumnName"]
%>
<%#
((DataRowView)Container.DataItem).Row["ColumnName"]
%>
<%#
((DataRowView)Container.DataItem)["adtitle"]
%>
<%#
((DataRowView)Container.DataItem)[n]
%>
<%#
((DbDataRecord)Container.DataItem)[0]
%>
<%#
(((èªå®ä¹ç±»å)Container.DataItem)).å±æ§.ToString()
%>ï¼å¦æå±æ§ä¸ºå符串类åå°±ä¸ç¨ToString()äºï¼
ä¸é¢è¿ä¸ä¸ªæ§è½æ好ã
//æ¾ç¤ºäºä½å°æ°
//<%#
DataBinder.Eval(Container.DataItem,
"UnitPrice",
"${ 0:F2}")
%>
//{ 0:G}代表æ¾ç¤ºTrueæFalse
//
//
<asp:Image
Width=""
Height=""
Border="0"
runat="server"
//
AlternateText='<%#
DataBinder.Eval(Container.DataItem,
"Discontinued",
"{ 0:G}")
%>'
//
ImageUrl='<%#
DataBinder.Eval(Container.DataItem,
"Discontinued",
"~/images/{ 0:G}.gif")
%>'
/>
//
//转æ¢ç±»å
((string)DataBinder.Eval(Container,
"DataItem.P_SHIP_TIME_SBM8")).Substring(4,4)
{ 0:d}
æ¥æåªæ¾ç¤ºå¹´ææ¥
{ 0:yyyy-mm-dd}
ææ ¼å¼æ¾ç¤ºå¹´ææ¥
{ 0:c}
è´§å¸æ ·å¼
---------------------------------------------------------
å¨æ¬ç« åé¢ï¼æ们å¨æ¨¡æ¿ä¸ä¸æä¸éå°è¿è¡¨è¾¾å¼ä»¥åEvalæ¹æ³ãEvalæ¹æ³æ¯ä¸ç§å®å¶è¿ç®ç¬¦ï¼å¨æ°æ®ç»å®è¡¨è¾¾å¼ç¨æ¥æ¹æ³æç»å®çæ°æ®é¡¹ä¸çå ¬å ±å±æ§ãåææç¨çEvalæ¹æ³æ¯ä¸ä¸ªASP.NET
2.0ææ¯æçç¹å¾ï¼å¦æå¨ASP.NET
1.xåºç¨ç¨åºä¸ä½¿ç¨ï¼åä¼äº§çä¸ä¸ªç¼è¯é误ã对äºASP.NETçææçæ¬ï¼æ们å¯ä»¥ä½¿ç¨ä¸ä¸ªå¨åè½ä¸ç¸å½çæ¹æ³ï¼è¯¥æ¹æ³ä¹ç§°ä¸ºEvalï¼ä½æ¯æ¥èªå¦ä¸ä¸ªç±»ââDataBinderã
éè¦æ示ï¼
éè¿Evalæ¹æ³(尽管å®æ¥èªDataBinderæPageç±»)ï¼å¯ä»¥è®¿é®æç»å®çæ°æ®é¡¹ä¸çå ¬å ±å±æ§ã让ææ¾æ¸ ä¸ä¸å ¬å ±å±æ§å¨è¯¥ä¸ä¸æä¸æä»ä¹ï¼ä»¥å为ä»ä¹æåææå®ä»¬å«åå±æ§ãä»»ä½ä¸ä¸ªå®ç°äºIEnumerableæ¥å£çç±»é½å¯ä»¥ç»å®å°ä¸ä¸ªæ§ä»¶ãå®é çç±»å表å½ç¶å æ¬DataTable(å ¶ä¸ä¸ä¸ªæ°æ®é¡¹å¨é»è¾ä¸å¯¹åºäºè¡¨è®°å½)ï¼ä½æ¯å®è¿å æ¬å®å¶éå(å ¶ä¸ä¸ä¸ªæ°æ®é¡¹å¯¹åºäºç»å®ç±»çä¸ä¸ªå®ä¾ã)Evalæ¹æ³æç»ä¼æ¥è¯¢è¯¥æ°æ®é¡¹å¯¹è±¡ä»¥å¾å°å®çå±æ§éã表示ä¸ä¸ªè¡¨è®°å½ç对象å°è¿åå®çåæ述符ï¼å ¶ä»å¯¹è±¡å°è¿åå®ä»¬çå ¬å ±å±æ§éã
DataBinderç±»æ¯ææ°æ®ç»å®è¡¨è¾¾å¼ççæå解æãå®çéæéè½½æ¹æ³Evalç¹å«éè¦ã该æ¹æ³ä½¿ç¨åå°æºå¶æ¥è§£æå计ç®ä¸ä¸ªè¿è¡æ¶å¯¹è±¡ç表达å¼ãEvalæ¹æ³ç客æ·å æ¬RADå·¥å ·ï¼è¯¸å¦Microsoft
Visual
Studio
.NET设计å¨åWebæ§ä»¶ï¼å®ä»¬ä»¥å£°æçæ¹å¼è°ç¨è¯¥æ¹æ³ç¨å¨ææ¹åçå¼å¡«å è¿äºå±æ§ã
1.
Evalæ¹æ³
DataBinder.Evalæ¹æ³çè¯æ³å¦ä¸ï¼
<%#
DataBinder.Eval(Container.DataItem,
expression)
%>
ä¸è¿°ä»£ç çæä¸çç¥äºç¬¬3个å¯éåæ°ã该åæ°æ¯ä¸ä¸ªå符串ï¼å å«æç»å®å¼çæ ¼å¼éæ©ãContainer.DataItem表达å¼å¼ç¨å¯¹è¯¥è¡¨è¾¾å¼è¿è¡è®¡ç®ç对象ã该表达å¼é常æ¯ä¸ä¸ªå符串ï¼è¡¨ç¤ºæ°æ®é¡¹å¯¹è±¡ä¸è¦è®¿é®çå段çå称ãå®å¯ä»¥æ¯ä¸ä¸ªå æ¬ç´¢å¼åå±æ§åç表达å¼ãDataItemå±æ§è¡¨ç¤ºå½å容å¨ä¸ä¸æä¸ç对象ã容å¨é常å³å°çæç该æ°æ®é¡¹å¯¹è±¡(ä¾å¦ï¼DataGridItem对象)çå½åå®ä¾ã
åé¢æ示ç代ç é常éå¤åºç°ï¼èä¸ä»¥ç¸åçå½¢å¼ãåªæ表达å¼åæ ¼å¼å符串å¨é¡µä¸é¡µä¹é´ä¼ææååã
2.
æ´ç®æ´çEval
DataBinder.Evalçåå§è¯æ³å¨ASP.NET
2.0ä¸å¯ä»¥è¢«ç®åï¼è¿ä¸ç¹æ们å¨åé¢çRepeater示ä¾ä¸å·²ç»çå°ãå¨ASP.NET
2.0ä¸ï¼åªè¦å¨ASP.NET
1.xä¸æ¥åå¦ä¸è¡¨è¾¾å¼çå°æ¹ï¼
<%#
DataBinder.Eval(Container.DataItem,
expression)
%>
å°±å¯ä»¥ä½¿ç¨ï¼
<%#
Eval(expression)
%>
ä¸ç¨è¯´ï¼ASP.NET
2.0ä¹æ¯å®å ¨æ¯æDataBinder对象çã
å¨<%#
...
%>çå®ç¬¦å åºç°çä»»ä½ä»£ç ï¼é½ä¼å¾å°ASP.NETè¿è¡åºçç¹æ®å¤çã让æ们ç®ååæä¸ä¸è¯¥ä»£ç ä¼åçä»ä¹ãç¼è¯è¯¥é¡µé¢æ¶ï¼Evalè°ç¨ä½ä¸ºä¸ä¸ªç¬ç«çè°ç¨æå ¥è¯¥é¡µé¢çæºä»£ç ä¸ãå¦ä¸ä»£ç 说æäºä¼åçä»ä¹ï¼
object
o
=
Eval("lastname");
string
result
=
Convert.ToString(o);
该è°ç¨çç»æ被转æ¢ä¸ºä¸ä¸ªå符串ï¼å¹¶ä»ç»ä¸ä¸ªæ°æ®ç»å®çæåæ§ä»¶ââDataBoundLiteralControlç±»çä¸ä¸ªå®ä¾ãç¶èææ°æ®ç»å®çæåæå ¥è¯¥é¡µçæ§ä»¶æ ä¸ã
å¨ASP.NET
2.0ä¸ï¼TemplateControlç±»(Pageçç¶ç±»)å®é ä¸æ°å¢äºä¸ä¸ªå为Evalçåä¿æ¤ç(ä½ä¸æ¯èæç)æ¹æ³ãå¦ä¸ä¼ªä»£ç 说æ该æ¹æ³çå·¥ä½æºå¶ï¼
protected
object
Eval(string
expression)
{
if
(Page
==
null)
throw
new
InvalidOperationException(â¦);
return
DataBinder.Eval(Page.GetDataItem(),
expression);
}
æ£å¦æ们å¯ä»¥çå°çï¼Evalæ¯å»ºç«å¨DataBinder.Evalæ¹æ³ä¹ä¸çä¸ä¸ªç®åå è£ ãDataBinder.Evalæ¹æ³ä½¿ç¨å½å容å¨çæ°æ®é¡¹è°ç¨ãé常ææ¾ï¼å½å容å¨çæ°æ®å¨æ°æ®ç»å®æä½ä¹å¤ä¸ºnullââå³ï¼å¨è°ç¨DataBindä¹åçè°ç¨æ ä¸ãè¿ä¸äºå®å¼èµ·äºEvalåDataBinder.Evalä¹é´çä¸ä¸ªå ³é®åºå«ã
éè¦æ示ï¼
TemplateControlçEvalæ¯ä¸ä¸ªæ°æ®ç»å®æ¹æ³ï¼å¨ä¸ä¸ªæ°æ®ç»å®æä½ä¸åªè½å¨ä¸ä¸ªæ°æ®ç»å®æ§ä»¶çä¸ä¸æä¸ä½¿ç¨ãç¸åï¼DataBinder.Evalæ¯ä¸ä¸ªå®å ¨æççæ¹æ³ï¼å¯ä»¥å¨ç¨åºä¸çä»»ä½å°æ¹ä½¿ç¨ãæ们é常å¨å®å¶çæ°æ®ç»å®æ§ä»¶çå®ç°ä¸ä½¿ç¨å®ãæå°å¨æ¬ä¹¦çå§å¦¹ç¯ãProgramming
Microsoft
ASP.NET
2.0
Applications:
Advanced
Topics
ãä¸ä»ç»å®ã
3.
è·å¾é»è®¤çæ°æ®é¡¹
åé¢ç»åºç说æ页é¢çEvalæ¹æ³çè¡ä¸ºç伪ç ï¼å±ç¤ºäºPageç±»çGetDataItemæ¹æ³ãå®æ¯ä»ä¹ï¼å¦åæè¿°ï¼è¿ä¸ç®åè¯æ³éç¨ä¸ä¸ªé»è®¤çContainer.DataItemä¸ä¸æ对象ãGetDataItemåªä¸è¿æ¯è¿å该对象çå½æ°ã
æ´ç²¾ç¡®å°è®²ï¼GetDataItemæ¯è·è¸ªé¡µé¢çå½åç»å®ä¸ä¸æçåºäºæ çæºå¶çç»ç¹ã该æ§ä»¶æ ä¸çæ¯ä¸ªæ§ä»¶å¨è°ç¨åDataBindæ¹æ³æ¶åå ¥è¯¥æ ä¸ãDataBindæ¹æ³è¿åæ¶ï¼æ§ä»¶ä»è¯¥æ ä¸å¼¹åºãå¦ææ æ¯ç©ºçï¼å¹¶ä¸ä¼å¾ä»¥ç¼ç¨çæ¹å¼è°ç¨Evalæ¹æ³ï¼åGetDataItemæåºä¸ä¸ªæ æçæä½å¼å¸¸ãæ»ä¹ï¼æ们åªè½å¨æ¨¡æ¿ä¸ä½¿ç¨Evalç®åæä½ï¼å¦æéè¦å¨ä»£ç ä¸çä»»ä½å ¶ä»å°æ¹è®¿é®ä¸ä¸ªæ°æ®é¡¹çå±æ§ï¼åå©ç¨DataBinder.Evalæ¹æ³ï¼å¹¶æ¾å¼å°æåºæ°æ®é¡¹å¯¹è±¡ã
æ示
å¦åæè¿°ï¼é常åªæå¨å®å¶çæ°æ®ç»å®æ§ä»¶ç代ç ä¸æéè¦ç´æ¥è°ç¨DataBinder.Evalæ¹æ³ã(æå¨Programming
Microsoft
ASP.NET
2.0
Applications:
Advanced
Topicsä¸ä»ç»äºå®å¶æ§ä»¶ã)ç¶èï¼å¦æåçè¿ç§æ åµï¼å¯è½éè¦éè¿è°ç¨DataBinder.GetPropertyValueæ¹æ³æ¥ä¿åå 个å é¨è°ç¨åCPUå¨æãæç»ï¼è¿å®å ¨æ¯ç±DataBinder.Evalå®æçã
å ³äº.netä¸çrepeater
repeater使ç¨çæ¹æ³è·datalistå·®ä¸å¤çï¼
ç®å示èä¸ä¸ªï¼
<asp:Repeater id="Repeater_Test" runat="server">
<HeaderTemplate>UserID UserName UserPWD</HeaderTemplate>
<ItemTemplate>
<br /><%#DataBinder.Eval(Container.DataItem,"userID") %>
<%#DataBinder.Eval(Container.DataItem,"username") %>
<%#DataBinder.Eval(Container.DataItem,"password") %>
</ItemTemplate>
</asp:Repeater>
---------------以ä¸æ¯Default.aspxæºç å¤--------
private DataTable DataTableToRepeater()
{
//èªå·±çæä¸ä¸ªDataTableç»Repeapterå½ä½æ°æ®æº
DataTable dt = new DataTable();
dt.Columns.Add("userID");
dt.Columns.Add("username");
dt.Columns.Add("password");
for (int i = 1; i < ; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = "User" + i.ToString();
dr[2] = "PWD" + i.ToString();
dt.Rows.Add(dr);
}
return dt;
}
--------------为äºæ¹ä¾¿è°ç¨ï¼ç¹æåäºä¸ä¸ªDataTable---------
çªä½å è½½æ¶
if (!IsPostBack)
{
Repeater_Test.DataSource = DataTableToRepeater();
Repeater_Test.DataBind();
}
-----------------çªä½å è½½------------------
UserID UserName UserPWD
1 User1 PWD1
2 User2 PWD2
3 User3 PWD3
4 User4 PWD4
5 User5 PWD5
6 User6 PWD6
7 User7 PWD7
8 User8 PWD8
9 User9 PWD9
-----------ç»æåºè¯¥æ¯è¿æ ·ç-----------
asp.net 自定义控件拖动不了
选中你页面中的所有控件:点击菜单上的"布局"-->"位置"-->"绝对",设置为绝对定位之后,在将你的源码海螺壳源码控件拖放到相应位置就能解决了,否则的控件控件codeblocks怎样导入源码话你只能通过CSS样式表或者直接通过"源"来控制控件的位置...