燕君 的个人资料White And Blue照片日志列表 工具 帮助

日志


1月6日

multiview控件

 multiview控件,实际上是有点象在c/s开发中很常见的tabcontrol控件,可以在一个页面中,放置多个"view"(我们称为选项卡),比如可以用multiview控件,可以让用户在同一页面中,通过切换到每个选项卡,从而看到要看的内容,而不用每次都重新打开一个新的窗口。
然而对Panel 的 Visible属性进行控制也可以完成这个工作,只是说用这个更专业吧!

未选择某个 View 控件时,该控件不会呈现到页面中。但是,每次呈现页面时都会创建所有 View 控件中的所有 Web 服务器控件的实例,并且将这些实例的值存储为页面的视图状态的一部分。

比如我们在用户注册中,不希望一次出现很多要填写的项,怎么做呢?那就可以用到这个,本来开始都作出来了,可惜做注册的话必须用到验证控件和存入数据库,所以暂时不做,希望大家理解,我之所以把这个系列的控件都分这么细,完全不是我无聊,我只是想尽量摸索每个控件的功能,毕竟如果我们把每个控件的功能都学得比较通了,那在实际运用中能够节约很多时间和网络带宽,我们说做程序特别是WEB程序,不能只考虑完成了什么功能,应该考虑如何用做恰当的控件来节约开发时间和页面体积,我常常说要完成一个功能至少有两种途径,但是总有一种是尽量兼顾到各方面的,例如我们说把注册分开几个阶段,可以完成的控件就多了,panel,PlaceHolder,Wizard,当然还有我们即将讲的multiview,如何抉择才能最好呢?这必须我们对控件本身比较了解才行!好了,不废话了.

有点需要注意的是,multiview中的View完全是按照排列来定的索引,并不是你给他的ID.

当然也可以通过URL 传递参数,总之一句话,只要你把索引值传给了他,就成

通过将 MultiView 控件的 ActiveViewIndex 属性设置为要显示的 View 控件的索引值,可以在视图间移动。MultiView 控件还支持可以添加到每个 View 控件的导航按钮。

若要创建导航按钮,可以向每个 View 控件添加一个按钮控件(Button、LinkButton或 ImageButton )。然后可以将每个按钮的 CommandName 和 CommandArgument 属性设置为保留值以使 MultiView 控件移动到另一个视图。下表列出了保留的 CommandName 值和相应的 CommandArgument 值。

CommandName 值 CommandArgument 值

NextView

(没有值)

PrevView

(没有值)

SwitchViewByID

要切换到的 View 控件的 ID。

SwitchViewByIndex

要切换到的 View 控件的索引号。

<%...@ Page Language="VB" AutoEventWireup="false" CodeFile="MultiView.aspx.vb" Inherits="MultiView" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>无标题页</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
            
<asp:ListItem Value="0">view1</asp:ListItem>
            
<asp:ListItem Value="1">view2</asp:ListItem>
            
<asp:ListItem Value="2">view3</asp:ListItem>
        
</asp:DropDownList>
        
<br>
        
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
            
<asp:View ID="View1" runat="server">
                111111111111111111111111111
<br />
                
<asp:Button ID="Button1" runat="server" CommandName="NextView" Text="next" />
                
<asp:Button ID="Button5" runat="server" CommandArgument="View3" CommandName="SwitchViewByID"
                    Text
="last" /></asp:View>
            
<asp:View ID="View2" runat="server">
                222222222222222222222222222
<br />
                
<asp:Button ID="Button2" runat="server" CommandName="PrevView" Text="pre" />
                
<asp:Button ID="Button3" runat="server" CommandName="NextView" Text="next" /></asp:View>
            
<asp:View ID="View3" runat="server">
                333333333333333333333333333
<br />
                
<asp:Button ID="Button4" runat="server" CommandArgument="0" CommandName="SwitchViewByIndex"
                    Text
="first" />
                
<asp:Button ID="Button6" runat="server" CommandName="preview" Text="pre" /></asp:View>
        
</asp:MultiView></div>
    
</form>
</body>
</html>
Partial Class MultiViewClass MultiView
    
Inherits System.Web.UI.Page

    
Protected Sub Page_Load()Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load
        
If Request.QueryString("id"<> "" Then
            MultiView1.ActiveViewIndex 
= Convert.ToInt32(Request.QueryString("id"))
        
End If
    
End Sub


    
Protected Sub DropDownList1_SelectedIndexChanged()Sub DropDownList1_SelectedIndexChanged(ByVal sender As ObjectByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        MultiView1.ActiveViewIndex 
= Convert.ToInt32(DropDownList1.SelectedValue)
    
End Sub

End Class

visualStudio2005设计视图打不开

gdiplus.dll 保证在
c:\WINNT\Microsoft.NET\Framework\V2.0.50727
c:\Program Files\Visual Studio 8\Common7\Packages
两个文件夹中都有
然后
"开始"-"运行" devenv /ResetSkipPkgs

 

8月20日

textarea格式设置

说明:
一般textarea提交到数据库,直接在显示有些换行等格式会丢失。
为了解决这个问题,输出的时候不妨也用textarea,但是必须使textarea的显示格式如一般输出
参数设置如下:
<textarea name="textarea" cols="90" readonly wrap="PHYSICAL" style="border: none;overflow: visible;height: auto;"><%=rs("NewsContent")%></textarea>
8月12日

把所有的textbox值为空

//和空灵共同进步 
//把所有的textbox值为空
//this.Controls是所有的控件的集合,方法2中直接第1次获得的是Control的集合,第二次才是textbox对象  ,方法1中则去第1个集   
// 方法1  
foreach( Control rc in this.Controls[1].Controls )
   {
    if(rc is TextBox)
    ((TextBox)rc).Text="";
   }
//
      方法2:
 foreach(Control rc in this.Controls)
   {
    if(rc is TextBox)
    ((TextBox)rc).Text="";
    else
   foreach(Control sc in rc.Controls)
                if(sc is TextBox)
    ((TextBox)sc).Text="";
   }
8月11日

这个方法更简单好懂

csdn上 cityhunter172(寒羽枫) 提供
在 Page_Load 中
    if(!IsPostBack)
   {
      this.TextBox1.Attributes["onkeydown"]="clickBtn('Button1')";
      this.TextBox2.Attributes["onkeydown"]="clickBtn('Button2')";
   }
在页面中加入脚本
<script language=javascript>
<!--
     function clickBtn(id)
     {
         var btn = document.getElementById(id); //根据 ID 找到 Button
         if(btn== null){return;} //没找到,则返回
         if (event.keyCode ==13 )   //按下的是回车键
         {
           btn.click();
           event.returnValue = false; //阻止回车键的生效
         }        
     }
//-->
</script>