位置:海鸟网 > IT > ASP.NET >

个性设计ASP.NET应用程序的七大绝招 (2)

3. DataList使用不同风格的模板
这招也非常实用,你可以制作两个不同的模板或表现形式,分别以.ascx控件的形式保存,运行时根据某个条件动态的选择使用其中的一个模板,另外ScottGu认为ItemDataBound方法也可以定制你显示的表现,比如加亮某个元素或是加一个促销广告图等等。





  

Dim theme As Stringtheme = DropDownList1.SelectedValueDataList1.ItemTemplate = Page.LoadTemplate(theme & ".ascx") ---CoolDataList1.DataSource = DSDataList1.DataBind()



4. 设置服务器端控件的焦点


Private Sub SetFocus(ByVal controlToFocus As Control)Dim scriptFunction As New StringBuilderDim scriptClientId As StringscriptClientId = controlToFocus.ClientIDscriptFunction.Append("<script language='javascript'>")scriptFunction.Append("document.getElementById('" & scriptClientId & "').focus();")scriptFunction.Append("</script>")RegisterStartupScript("focus", scriptFunction.ToString())End SubPrivate Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadIf (Page.IsPostBack = False) ThenSetFocus(TextBox1)End IfEnd Sub