Asp.Netフロントコールバックグラウンド変数

9103 ワード

1.Asp.Net          : < %=...%>< %#... %>< % %>< %@ %>     

 : < %#... %>:       DataBind()        ,      

 : < %# Container.DataItem("tit") %>

< %= %>:          ,         

 :

*.aspx : < %= aaa %>

*.cs : protected string aaa="  ";

< % %>:               *.aspx *.ascx          

 :

< %

for(int i=0;i<100;i++)

{

Reaponse.Write(i.ToString());

}

%>

< %@ %>  *.aspx            ,

 :

< %@ Import namespace="System.Data"%>

2.          ?

 :  Bind   ,   DropDownList,DataList,DataGrid,ListBox         ,         ArrayList(  ),Hashtable(   ),DataView(    ),DataReader   ,            ,    DataTable       :)

3.DataBind,     ,        String,          ?

DataBinder.Eval(Container.DataItem,"     ","  ")

    "  "    ,       ,Container.DataItem       ,"    "    Integer,String,Boolean     .

4.      :

< % @ Import Namespace="System.Data" %>        

< % @ Import Namespace="System.Data.ADO" % >   ADO.net ;    

< % @ Import Namespace="System.Data.SQL" %> SQL Server      

< % @ Import Namespace="System.Data.XML" %>      XML  

< % @ Import Namespace="System.IO" %>        

< % @ Import Namespace="System.Web.Util" %>          

< % @ Import Namespace="System.Text" %>        

5.Connections(SQLConection    ADOConnection)        :

| ConnectionString              

| ConnectionTimeout                ,       

| DataBase                      

| DataSource      DSN,       :)

| Password        

| UserID         

| State          

| Open()     

| Close()     

| Clone()       。(  ,    Connection    )

  :

SQLConnection myConnection = new SQLConnection();

myConnection.DataSource = "mySQLServer";

myConnection.Password = "";

myConnection.UserID = "sa";

myConnection.ConnectionTimeout = 30;

myConnection.Open();

myConnection.Database = "northwind";

myConnection.IsolationLevel = IsolationLevel.ReadCommitted

6.Command        

| ActiveConnection        Connections

| CommandText    SQL       (StoredProcedure) 

| CommandTimeout        

| CommandType Command     (StoredProcedure,Text,TableDirect)  ,  Text

| Parameters          

| Execute()   SQL       

| ExecuteNonQuery()   ,          

| Clone()   Command

  :

string mySelectQuery = "SELECT * FROM Categories ORDER BY CategoryID";

stringmyConnectString="userid=sa;password=;database=northwind;server=mySQLServer";

SQLCommand myCommand = new SQLCommand(mySelectQuery);

myCommand.ActiveConnection = new SQLConnection(myConnectString);

myCommand.CommandTimeout = 15;

myCommand.CommandType = CommandType.Text;< /FONT >

7.            :

1.MyConnection.Open(); //    

MyConnection.Close();

2.MyCommand.ActiveConnection.Open();

MyCommand.ActiveConnection.Close()

8.  DataSet,       、  、      

a.    

DataRow dr=MyDataSet.Tables["UserList"].NewRow();

dr["UserName"] = "  ";

dr["ReMark"] = "100";

dr["Comment"] = "  MM";

MyDataSet.Tables.Rows.Add(dr);

b.    

MyDataSet.Tables["UserList"].Rows[0]["UserName"]="    ";

c.    

MyDataSet.Tables["UserList"],Rows[0].Delete();

d.    

if(MyDataSet.HasErrors)

{

MyDataSet.RejectChanges();

}

e.  DataSet     

if(MyDataSet.HasChanges)

{

//    

}else{

//      ,      ,     

}

f.     

MyComm.Update(MyDataSet); //          

MyComm.Update(MyDataSet,"UserList"); //     

9.DataGrid      

AllowPaging="True" //      ,       。   ,      。

PageSize="5" //           ,    ,     10 。

PagerStyle-HorizontalAlign="Right" //          ,   Left

PagerStyle-NextPageText="   " // <>            

PagerStyle-PrevPageText="   "

PagerStyle-Mode="NumericPages" // <>  123    

10.        ,          

    :< %=DataGrid1.CurrentPageIndex+1%>

    :< %=DataGrid1.PageCount%>

11.     

       "    ASP.Net(14)"     

12.            

IValidator val;

foreach(val in Validators)

{

Val.IsValid = true;

}

13.          

IValidator val;

foreach(val in Validators)

{

Val.Validate();

}

14.       

< %@ Page Language="c#" clienttarget=downlevel %>

15.Repeater、DataList DataGrid    "

              Web       ,    、   、    、  

       。 Repeater             HTML     .

16.Server.Execute("another.aspx") Server.Transfer("another.aspx")  :

Execute             ,           

Transfer             

17.XML           ,      *.xsl   ,     xmlns   xml            ,    :

18.XML     

FileStream myfs=new Filestream(Server.MapPath("xmldtagrid.xml"),FileMode.Open,FileAccess.Read);

StreamReader myreader=new StreamReader(myfs);

DataSet myds=new DataSet();

myds.ReadXml(myreader);

19.        RegularExpressionValidator

     

^        

$        

[]                      

\W        

\d{} "\d"           ,{}              

+                       

  :      (  @ ,  .com/.net/.org/.edu  )

validationexpression="^[\w-]+@[\w-]+\.(com|net|org|edu)$"

20.DataGrid           :

  :DataKeyField="userid" // userid     ,              ,        DataGrid   

SqlCommand.Parameters["@userid"].Value=dg.DataKeys[(int)e.Item.ItemIndex]; //           (                    ) 

SqlCommand.Parameters["@fname"].Value=((TextBox)e.Item.Cells[2].Controls[0]).Text; //           

21.     :

a.    (ASP      )

(I).     ,    ,    /  . < % @Control Language="C#" Debug="True" %>  @Control               

(II)    *.ascx  , a.ascx.

(III).  :  <%@Register Tagprefix="MyFirstControl" TagName="MyLbl" Src="a.axcs" %>

//Tagprefix      , ASP:TextBox  ASP

//TagName            

//Src       

  :

b.  C#       

(I).        ,    Control,    *.cs, a.cs.

(II).          : csc /t:library /r:System.dll,System.Web.Dll a.cs

//library  C#        

// /r:System.dll System.Web.Dll  C#           

(III).   dll    bin   

(IV).  : < % @Register TagPrefix="Mine" Namespace="MyOwnControls" Assembly="a" %>

22.        :

public class MyCompositin:Control,INamingContainer //INamingContainer:              ,         {} //        

this.EnsureChildControls();//                  ,                 

CreateChildControls

23.Button/LinkButton/ImageButton/HyperLink     ?

1.Button ImageButton           .

2.Hyperlink         

3.LinkButton                     

24.    

  :

1.     :              < %@ Page Trace="True" TraceMode="SortByCategory/SortByTime" %>

     :

Trace.Write("          ");

Trace.Warn("          "); // Trace.Write  ,       

         

  : if(Trace.IsEnabled) { Trace.Warn("     ")}

2.        :  Web.config     

25.    :

1.    :

I.    :   < %@ OutputCache Duration="120" VaryByParam="none" %>           

  :            ,      

II.      :

     System.Web.HttpCachePolicy     

(1). Response.Cache.SetExpires(DateTime.Now.AddSeconds(120)); //             ,    //     

(2). Response.Cache.SetExpires(DateTime.Now.AddSeconds(120));

Response.Cache.SetSlidingExpiration(true); //"    ",            ,      //      

  :           ,      sliding expiration(    ).

2.    :

(1).DataView mySource; (2). mySource  ;

(3).Cache["myCache"]=mySource; (4).mySource=(DataView)Cache["myCache"]

26.  :                  : XCOPY //XOPY       ,       

26.       

1.

protected void ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)

{

System.Web.UI.WebControls.ListItemType elemType = e.Item.ItemType;

if (elemType == System.Web.UI.WebControls.ListItemType.Pager)

{

TableCell pager = (TableCell) e.Item.Controls[0];

for (int i=0; i {

Object o = pager.Controls[i];

if (o is LinkButton)

{

LinkButton h = (LinkButton) o;

h.Text = " " + h.Text + " ";

}

else

{

Label l = (Label) o;

l.Text = String.Format("[ {0} ]", l.Text);

}

}

}

}

2.   :zhangzs8896(  )

private void MyDataGrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)

{

ListItemType lit_item=e.Item.ItemType;

TableCell tc_item=(TableCell)e.Item.Controls[0];

if (lit_item==ListItemType.Pager)

{

for (int i=0;i {

object obj_item=tc_item.Controls[i];

if (obj_item is LinkButton)

{

LinkButton lbn_item=(LinkButton)obj_item;

lbn_item.Text=lbn_item.Text;

lbn_item.Font.Size=10;

lbn_item.ForeColor=Color.FromName("#666666");

lbn_item.Attributes.Add ("onmouseover","currentcolor=this.style.color;this.style.color='#14AC05'");

lbn_item.Attributes.Add("onmouseout","this.style.color=currentcolor");

}

else

{

Label lbl_item=(Label)obj_item;

lbl_item.ForeColor=Color.Blue;

lbl_item.Font.Bold=true;

lbl_item.Font.Underline=true;

lbl_item.Text="" + lbl_item.Text + "";

lbl_item.Font.Size=10;

}

}

}

}