Asp.Net 网页开发

1. 对ispostback的理解:
 
每当你对控件进行操作,或触发事件时,页面都要提交一次。也就是页面要重新加载一次,每次加载时都会先运行:
   public   void   Page_Load(Object   src, EventArgs   e)  
  {  
  if(!IsPostBack)  
        {  
          Me.LoadData()  //页面第一次加载时要执行的事件,当不是第一次加载时不执行此事件  
          }  
  }  
  事件。  
  !IsPostBack表示页面是第一次加载时,所要执行的事件。  
      IsPostBack表示页面是重新加载或返回时,要执行的事件。   
  简单的说就是可以避免你的初始化代码在叶面刷新是重复执行。
 
2. 显示数据:
Private Sub LoadData()
        Dim objCs As New CS             //辅助类,其中自己写函数
        Dim objDs As New DataSet
        Dim objDv As DataView
        objDs = objCs.GetPrice          //调用方法读取数据,存入objDs
        If objDs.Tables.Count > 0 AndAlso objDs.Tables(0).Rows.Count > 0 Then
            objDv = objDs.Tables(0).DefaultView
            objDv.Sort = ViewState("sort")
           
            With Me.dgPrices              //DataGrid
                .Visible = True
                .DataSource = objDv
                .DataBind()                  //绑定数据
            End With
           
            If Me.dgPrices.PageCount > 1 Then
                Me.dgPrices.PageStyle.Visible = True    //大于一页时,显示页码
            Else
                Me.dgPrices.PageStyle.Visible = False
            End If
        Else
            Me.dgPrices.Visible = False    //未收到数据,不显示
        End If
       
其中,调用的方法为:
Public Function GetPrice() As DataSet
        Me.SelectCommand = Nothing
        With Me.SelectCommand
            .CommandType = CommandType.StoredProcedure
            .CommandText = "price_get"      //存储过程
        End With
        Return Me.QueryData("GetPrice")    //执行了连接操作并返回dataset型数据
    End Function
       
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s