gsyj2.aspx

来自「《精通ASP.NET网络编程》附带实例」· ASPX 代码 · 共 81 行

ASPX
81
字号
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.SqlClient"%>
<html>
<Script language="C#" runat="server">
    void GetSales_Click(Object Sender,EventArgs E) 
      {
        DataSet DS;
        SqlConnection MyConnection;
        SqlDataAdapter MyCommand;
        String ConnStr;
        MyConnection =new SqlConnection("server=(local)\\NetSDK;database=mydb;Trusted_Connection=yes");
        ConnStr="select * from mytable where 销售日期>='"+BeginDate.SelectedDate.ToShortDateString()+"' and 销售日期<='"+EndDate.SelectedDate.ToShortDateString()+"'";
        MyCommand = new SqlDataAdapter(ConnStr, MyConnection);
        DS = new DataSet();
        MyCommand.Fill(DS, "mytable");
        MyDataGrid.DataSource=DS.Tables["mytable"].DefaultView;
        MyDataGrid.DataBind();
      }
</Script>
<body>
  <form runat="server">
    <h3><font face="Verdana">公司销售业绩查询系统</font></h3>
    <table width="700">
      <tr>
        <td valign="top" >
          <b>开始日期</b>
          <ASP:Calendar id="BeginDate" 
             BorderWidth="2"
             BorderColor="lightblue"
             Font-Size="8pt" 
             TitleStyle-Font-Size="8pt" 
             TitleStyle-BackColor="#cceecc" 
             DayHeaderStyle-BackColor="#ddffdd"
             DayHeaderStyle-Font-Size="10pt" 
             WeekendDayStyle-BackColor="#ffffcc" 
             SelectedDate="1/1/2000"
             VisibleDate="1/1/2000"
             SelectedDayStyle-BackColor="lightblue"
             runat="server"/>
        </td>
        <td valign="top" >
          <b>结束日期</b>
          <ASP:Calendar id="EndDate" 
             BorderWidth="2"
             BorderColor="lightblue"
             Font-Size="8pt" 
             TitleStyle-Font-Size="8pt" 
             TitleStyle-BackColor="#cceecc" 
             DayHeaderStyle-BackColor="#ddffdd"
             DayHeaderStyle-Font-Size="10pt" 
             WeekendDayStyle-BackColor="#ffffcc" 
             SelectedDate="7/23/2001"
             VisibleDate="7/23/2001"
             SelectedDayStyle-BackColor="lightblue"
             runat="server"/>
        </td>
        <td valign="top" style="padding-top:20">
          <input type="submit" OnServerClick="GetSales_Click" Value="查询销售业绩" runat="server"/><p>          
        </td>
      </tr>
      <tr>
        <td colspan="3" style="padding-top:20">
            <ASP:DataGrid id="MyDataGrid" runat="server"
              Width="500"
              BackColor="#ccccff" 
              BorderColor="black"
              ShowFooter="false" 
              CellPadding=3 
              CellSpacing="0"
              Font-Name="Verdana"
              Font-Size="8pt"
              HeaderStyle-BackColor="#aaaadd"
              EnableViewState="false"
            />
        </td>
      </tr>
    </table>
  </form>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?