·建站首页 ·钻石 ·繁體
您的位置: 中国建站之家 -> 网站开发设计 -> .Net教程 -> 个性设计ASP.NET应用程序的七大绝招 (2)

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

作者:未知  来源:www.jz123.cn  发布时间:2005-11-23 5:15:15  发布人:jz123

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

将本文收藏到QQ书签与更多好友分享