人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

May 29, 2006

webcast_How do I Video Series_Tips and Tricks

Filed under: ASP.NET

How do I? Video Series : Tips and Tricks (hilo_tips_final.wmv)
http://asp.net/default.aspx?tabindex=4&tabid=3000
http://asp.net/learn/howdoi/default.aspx?tabid=63

通过代码加解密的connection string

public void EncryptConfig(bool bEncrypt)
{
    string path = "/tricks";
   
    Configuration config = WebConfigurationManager.OpWebConfiguration(path);
    ConfigurationSection appSettings = config.GetSection("connectionString");
   
    if(bEncrypt)
    {
        appSettings.SetionInformation.ProtectSection("DataProtectionConfigurationProvider");
    }
    else
    {
        appSettings.SetionInformation.UnprotectSection();  
    }
    config.Save();
}

保持滚动条的当前位置
    <%@ Page MaintainScrollPostionOnPostback = "true">
   
跨页面提交
    设置page1的PostBackUrl ="page2.aspx"
    设置page1的form1的
        DefaultButton和DefaultFocus
       
    在page2.aspx的page_load中写下:
    if(!Page.IsPostBack)
    {
        TextBox t = (TextBox)PreviousPage.FindControl("textbox1");
        this.lable1.Text = t.Text;
    }
   
使用BulletedList data binding到xml.
   
   
File Upload Control
   
    if(fileUpload1.HasFile)
    {
        fileUpload1.SaveAs("C:\upload\"+ fileUpload1.FileName);
    }

URL mapping 把一个很复杂的url map成一个简单的url.
    <System.web>
        <add url="…" mappedUrl="…">
    <System.web>
   
使用MultiView控件

webcast_How do I Video Series_Data Access

Filed under: ASP.NET

How do I? Video Series : Data Access(hilo_data_final.wmv)
http://asp.net/default.aspx?tabindex=4&tabid=3000
http://asp.net/learn/howdoi/default.aspx?tabid=63

共14分钟,演示了
1. 使用mdf文件, 从pubs数据库authots表导入数据

2. 生成了数据访问层: 生成connection string , 生成和配置 dataset,

3. 针对dataset的data binding
共两个页面: default.aspx 和 details.aspx

defautl 页面上有一个combo box, 一个gridview,演示了级联数据显示.
        gridview 还添加了detail url,指向 details页面,显示详细信息.

details页面,使用了DetailsView, 根据url中传来的参数,显示详细信息.

详细步骤:
//—-使用mdf文件
1. 在vs 2005 中可以直接生成mdf文件, 生成table,但不能执行 create table 等sql语句.
使用 SQL Server Management Studio Attach上mdf文件,可进行高级操作

//—-操作dataset
dataset会被存放在app_code目录中

可把table或table中的field从db explorer上drag到date set的design view上来生成table adapter

按照Table Adapter Configuration的提示可生成connection string 和用于select, update, delete
的sql 语句.
select 语句的where 子句通过设置filter 来实现,比如把filter设为 Filter = @state,会生成语句
where(state = @state)

完成后可使用preview data 菜单来进行测试, Cool!

//—- data binding
使用dataset,要在为control设置数据源时,选择object.
combo box 用来显示state,并用于引发dataview的变化, 所以combo box 的"Enable AutoPostback" 要设为true.
注意data source 的参数可以来自其他control, 也可以来自url.
把一个page drag到另一个page上可以直接生成一个link.

//如何实现details page
1.给data view添加一个column
2.设置column类型为HyperLinkField
3.设置HyperLink URL
  get url from data field : authorId
  url fromat string : Detauls.aspx?AuthorId={0}
4.在DataSet中添加一个query: GetDataByAuthorID
5.生成details page,添加DetailsView,设置datasource 为object,
  设置Parameter source为QueryString, QueryStringField为AuthorId
  和dataview的HyperLink column的设置对应.

webcast_How do I Video Series_Create a Full-Featured Customer Login Portal

Filed under: ASP.NET

How do I? Video Series : Create a Full-Featured Customer Login Portal(hilo_intro_final.wmv)
http://asp.net/default.aspx?tabindex=4&tabid=3000
http://asp.net/learn/howdoi/default.aspx?tabid=63

全面介绍asp.net2.0 功能

1.DataView的data binding
使用northwinds.mdf数据库
在配置dataview 的data source时使用 select statement, 并设置 where clause,
指定source为QueryString, QueryString Field为CustomerID.
或指定source为control, ControlID为gridview1

如果要使用主从两个dataview,
需要在主gridview中设置DataKeyName,并添加select column

在从gridview中设置其data source的查询语句的source为control, ControlID为gridview1

2.使用Theme
App_Themes下建立某个theme对应的folder,将Theme相关的文件(包括.css,.skin, 图片) 放到文件夹中.

skin文件的写法:
<asp:TextBox BackColor=”Green” Runat=”Server” />
<asp:TextBox SkinID=”BlueTextBox” BackColor=”Blue” Runat=”Server” />
<asp:BulletedList BulletStyle=”CustomImage” BulletImageUrl=”BulletImages/OrangeBullet.gif” Runat=”Server” />
第一个skin不包含 SkinID,被当成默认skin,适用于所有的TextBox.

<system.web>
<pages theme=”ThemeName” styleSheetTheme=”ThemeName”/>
</system.web>

在某个Page中使用theme
<%@ Page Theme=”ThemeName” %>
<%@ Page StyleSheetTheme=”ThemeName” %>

将主题应用于页面时,主题中所设置的任何控件属性都优先于页面中所设置的任何属性。
例如,如果主题指定所有 TextBox 控件的背景都应当显示为橙色,那么即使个别 TextBox
控件的 BackColor 属性具有不同的值,页面中所有 TextBox 控件的背景也仍然都将显示为
橙色。

在 ASP.NET 中,优先级的顺序是:
Theme,包括 Web.config 文件中设置的主题。
Page
StyleSheetTheme
比如skin文件中定义:
<asp:Label runat=”server” ForeColor=”red” Font-Size=”14pt” Font-Names=”Verdana” />
Page中将Lable1.ForeColor 设置为 blue。
如果使用<pages theme=”ThemeName”>Lable1为 red,
如果使用<pages StyleSheetTheme=”ThemeName”>Lable1为 blue,

动态加载Theme

Protected void Page_PreInit(object sender, EventArgs e)
{
switch (Request.QueryString[”theme”])
{
case “Blue”:
Page.Theme = “BlueTheme”;
break;
case “Pink”:
Page.Theme = “PinkTheme”;
break;
}
}

3. 使用master page
快速修改一个page:
1. 删光所有代码,只剩<%@page
2. 在<%@page 中写 MasterPageFile=”"
3. 切换到design view, 选择”Create Custom Content”

4. 用户登录,权限
使用web site admin tool生成config, user account, user role
使用loginview
使用LinginStatus
使用CreateUserWizard

5. Site map
Web.sitemap
使用TreaView ,将datasource设为SitemapDatasource
使用SiteMapPath
在web.config中使用 securityTrimmingEnable=”true”,可过滤掉用户无权访问的链接.

6. 使用 profile
类似app setting,但是保存在sqlserver 中
在web.config中添加
<profile>
<properties>
<add name =”FullName” defaultValue= “”>
</properties>
</profile>
使用:
//读
if(!page.IsPostBack)
{
TextBox1.Text = Profile.FullName;
}
//写
Profile.FullName = TextBox1.text

参考
演练:在 Visual Studio 中使用主题自定义网站
http://msdn2.microsoft.com/zh-cn/library/zcsbskx7.aspx






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham