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

- 中国WEB开发者网络 (http://www.webasp.net)
-- 技术教程 (http://www.webasp.net/article/)
--- 个性设计ASP.NET应用程序的七大绝招 (2) (http://www.webasp.net/article/28/27087.htm)
-- 作者:未知
-- 发布日期: 2005-11-22
3. DataList使用不同风格的模板
这招也非常实用,你可以制作两个不同的模板或表现形式,分别以.ascx控件的形式保存,运行时根据某个条件动态的选择使用其中的一个模板,另外ScottGu认为ItemDataBound方法也可以定制你显示的表现,比如加亮某个元素或是加一个促销广告图等等。





  
Dim theme As String
theme = DropDownList1.SelectedValue

DataList1.ItemTemplate = Page.LoadTemplate(theme & ".ascx") ---Cool
DataList1.DataSource = DS
DataList1.DataBind()


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


Private Sub SetFocus(ByVal controlToFocus As Control)
Dim scriptFunction As New StringBuilder
Dim scriptClientId As String

scriptClientId = controlToFocus.ClientID
scriptFunction.Append("<script language='javascript'>")
scriptFunction.Append("document.getElementById('" & scriptClientId & "').focus();")
scriptFunction.Append("</script>")
RegisterStartupScript("focus", scriptFunction.ToString())
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If (Page.IsPostBack = False) Then
SetFocus(TextBox1)
End If
End Sub


webasp.net