komatu

       暗  香  堂
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C#2.0学习笔记(3)

Posted on 2006-03-30 11:07  暗香堂  阅读(275)  评论(0)    收藏  举报
 

24VS .NET can handle inline source code within the ASPX file, and it offers a revised code-behind model called code-beside.

25If you're using Windows Server 2003, you'll need to enable the ASP.NET 1.2 (2.0) ISAPI extension manually. Start the Internet Service Manager, choose Web Service Extensions, activate ASP.NET v1.2 ISAPI, and click Enable.

26Code-behind was smart, but from an object-based view it was far from perfect. The designed ASPX page was derived from a class that was generated in parts by the development environment. You had to declare controls in both files, and manual changes often resulted in problems. There are a lot of good reasons to move away from code-behind.

 

The solution is code-beside, which is supposed to make everything better, brighter, and of course more object oriented. This is what the ASP.NET team promises. Instead of using the class derivation as it was up to now, the design file and the source code file are created as partial classes that will be merged by the compiler (I describe partial classes in Chapter 1). This approach means that there's no automatically generated source code at all. Both files work hand in hand, and you can assign events directly in the server control tags.

27With ASP.NET you're no longer limited to one language per web site. You can now mix different .NET languages whenever you want. Does it make sense to write one page in C#, a second in VB .NET, and a third in J#? I don't know, but at least it's possible!

28.如何发布程序呢?没有Bin目录的话,难道需要aspx,cs文件一起发布?方法如下:

采用PreCompile方法aspnet_compiler –v / -p <source代码目录> <target发布目录>

生成的aspx文件内容为空,全部集成到DLL中了!!!但是代码用Reflector反编译后更容易阅读了???XenoCode2005可能会好些。国内最新的软件:MaxToCode可能更好,但是好像不能正常运行。

29.提示无法识别的属性“xmlns

iis没有注册asp.net2.0 而仍然是11的。

DOS C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215目录中运行

aspnet_regiis.exe -i 就好了

30The following six Data Source controls are currently shipped with ASP.NET 2.0:

SqlDataSource: Accesses SQL Server, OLE DB, ODBC, Oracle, and other database systems for which a custom .NET Data Provider exists (possible providers: MySQL, Firebird, etc.)

AccessDataSource: Enables you to work easily with Microsoft Access databases by specifying a filename

DataSetDataSource: Used with data sets

ObjectDataSource: Lets you visualize classes/objects directly

XmlDataSource: Used for XML files and documents

SiteMapDataSource: Recalls the new site map data structure

With the exception of the SiteMapDataSource controls, all the Data Source controls provide built-in caching. Please notice that caching with the SqlDataSource control will only work if the option DataSourceMode is set to DataSet.

31Note In some documentation or in Microsoft examples, you'll probably encounter something called a SmartGrid control. No, it's not a new, tricky control; it's just another name for the GridView control. The name hasn't been finalized, because of an obvious conflict with the product name of a third-party vendor.

32Many users prefer a confirmation before finally deleting a data record (see Figure 3-8). This is a matter of three easy steps:

Create a new CommandField column and activate ShowDeleteButton.

Convert the column to a TemplateField column.

Change to HTML view and assign a client-side method to the click event of the generated LinkLabel:

 

<asp:templatefield>

   <itemtemplate>

      <asp:linkbutton id="LinkButton1" runat="server"

           causesvalidation="False" commandname="Delete"

           text="Delete"

           onclientclick="return confirm('Are you sure you want ' +

                  'to delete this record?')">

      </asp:linkbutton>

   </itemtemplate>

</asp:templatefield>

33Combining GridView and DetailsView

<%@ page language="C#" %>

 

<html>

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form runat="server">

        <asp:gridview id="GridView1" runat="server"

            allowpaging="True"

            datasourceid="SqlDataSource1"

            allowsorting="True"

            autogeneratecolumns="False"

            datakeynames="CustomerID">

            <columnfields>

                <asp:boundfield sortexpression="CustomerID"

                    datafield="CustomerID" readonly="True"

                    headertext="CustomerID">

                </asp:boundfield>

                <asp:boundfield sortexpression="CompanyName"

                  datafield="CompanyName"

                  headertext="CompanyName">

                </asp:boundfield>

                <asp:boundfield sortexpression="ContactName"

                  datafield="ContactName"

                  headertext="ContactName">

                </asp:boundfield>

                <asp:commandfield showselectbutton="True">

                </asp:commandfield>

            </columnfields>

        </asp:gridview>

 

        <asp:sqldatasource id="SqlDataSource1" runat="server"

            ...

        </asp:sqldatasource>&nbsp;

 

        <asp:sqldatasource id="SqlDataSource2" runat="server"

            ...

            <selectparameters>

                <asp:controlparameter propertyname="SelectedValue"

                 controlid="GridView1">

                </asp:controlparameter>

            </selectparameters>

        </asp:sqldatasource>

 

         <asp:detailsview id="DetailsView1" runat="server"

            datasourceid="SqlDataSource2"

            autogeneraterows="False"

            datakeynames="CustomerID">

            <rowfields>

                <asp:boundfield sortexpression="CustomerID" datafield="CustomerID"

                    readonly="True"

                    headertext="CustomerID">

                </asp:boundfield>

                <asp:boundfield sortexpression="CompanyName"

                    datafield="CompanyName"

                    headertext="CompanyName">

                </asp:boundfield>

                <asp:boundfield sortexpression="ContactName"

                    datafield="ContactName"

                    headertext="ContactName">

                </asp:boundfield>

                <asp:commandfield showdeletebutton="True" showinsertbutton="True"

                  showeditbutton="True">

                </asp:commandfield>

            </rowfields>

        </asp:detailsview>

    </form>

</body>

</html>

 

 

 

---------------void Page_Load(object sender, System.EventArgs e)

{

    DetailsViewStatusEventHandler handler =

        delegate { this.GridView1.DataBind(); };

    this.DetailsView1.ItemInserted += handler;

    this.DetailsView1.ItemUpdated += handler;

    this.DetailsView1.ItemDeleted += handler;

}

34client-side population

35    <asp:objectdatasource

        id="ObjectDataSource1"

        runat="server"

        typename="PersonManager"

        selectmethod="SelectPersons"

        deletemethod="DeletePerson"

        updatemethod="Update"

        insertmethod="Insert">

        <insertparameters>

             <asp:parameter name="Id" type="Int32"></asp:parameter>

         </insertparameters>

    </asp:objectdatasource>