Asp.Net不使用CodeBehind的做法

// 引用命名空间

<% @ Import Namespace = " jmvt " %>
<% @ Import Namespace = " System.Data "   %>


<! DOCTYPE HTML PUBLIC  " -//W3C//DTD HTML 4.0 Transitional//EN "   >
< HTML >
 
< HEAD >
  
< title > smslist </ title >
  
< meta name = " GENERATOR "  Content = " Microsoft Visual Studio .NET 7.1 " >
  
< meta name = " CODE_LANGUAGE "  Content = " C# " >
  
< meta name = " vs_defaultClientScript "  content = " JavaScript " >
  
< meta name = " vs_targetSchema "  content = " http://schemas.microsoft.com/intellisense/ie5 " >


// 使用C#


  
< script language = " C# "  runat = " server " >
    
private   void  Page_Load( object  sender,System.EventArgs e)
    
{
  BindGrid();
    }

    
    
private   void  chgPage( object  source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
 
{
  dgList.CurrentPageIndex
=e.NewPageIndex;
  BindGrid(); 
 }

 
 
private   void  BindGrid()
 
{
  
string strQuery=string.Empty;
  
string strConn="server=(local);database=axoav2;uid=sa;pwd=123456";

  strQuery
+=" select a.mobile,a.content,a.recetime,sender=isnull(convert(varchar,b.username),N'未知') from jsdl a ";
  strQuery
+=" left join man b ";
  strQuery
+=" on a.mobile=b.mobile ";
  strQuery
+=" order by a.id desc ";

  
try
  
{
   dgList.DataSource
=SqlHelper.ExecuteDataset(strConn,CommandType.Text,strQuery);
   dgList.DataBind();
  }

  
catch(Exception ex)
  
{
   Response.Write(ex.ToString());
  }
 
 }


  
</ script >
  
< LINK href = " style1.css "  rel = " stylesheet " >
 
</ HEAD >
 
< body MS_POSITIONING = " GridLayout " >
  
< form id = " Form1 "  method = " post "  runat = " server " >
   
< table cellpadding = " 1 "  cellspacing = " 1 "  width = " 100% "  border = " 0 "  bgcolor = " #e0dfe3 " >
    
< tr bgcolor = " #ffffff " >
     
< td >
      
< asp:DataGrid id = " dgList "  runat = " server "  AutoGenerateColumns = " False "  width = " 98% "  ItemStyle - Height = " 25 "
       AllowPaging
= " True "  PageSize = " 10 "  OnPageIndexChanged = " chgPage " > // 只需要输入事件名称(不用参数)
        < PagerStyle HorizontalAlign = " Right "  Position = " TopAndBottom "  Mode = " NumericPages " ></ PagerStyle >
       
< ItemStyle Height = " 25px " ></ ItemStyle >
       
< Columns >
        
< asp:BoundColumn DataField = " mobile "  HeaderText = " 手机号码 " ></ asp:BoundColumn >
        
< asp:BoundColumn DataField = " content "  HeaderText = " 信息内容 " ></ asp:BoundColumn >
        
< asp:BoundColumn DataField = " recetime "  HeaderText = " 接收时间 " ></ asp:BoundColumn >
        
< asp:BoundColumn DataField = " sender "  HeaderText = " 发送人 " ></ asp:BoundColumn >
       
</ Columns >
      
</ asp:DataGrid >
     
</ td >
    
</ tr >
   
</ table >
  
</ form >

你可能感兴趣的:(asp.net)