shop.aspx

来自「asp.net经典案例资料」· ASPX 代码 · 共 46 行

ASPX
46
字号
<%@ Import Namespace="System.Data" %>
<html>
  <head>
    <title>Web Service Demo</title>
    <script language="C#" runat="server" >
    void Page_Load()
    {
      if(!IsPostBack)
      {
        Shop shop = new Shop();
        DataSet dataSet = shop.GetList();
        grid1.DataSource = dataSet;
        grid1.DataBind();
      }
    }
    
    void Grid_ItemCommand(object sender, DataGridCommandEventArgs arg) 
    {
      DataGridItem item = arg.Item;
      Shop shop = new Shop();
      string id = item.Cells[2].Text; 
      int count = int.Parse( ((TextBox)item.Cells[0].FindControl("txtCount")).Text );
      shop.OrderGood( id, count);
      Label1.Text += "<br/>" + item.Cells[3].Text + "-" + count.ToString();
    }
    </script>
  </head>

  <body>
  <form id="form1" runat="server">
  <h3>网上商店 Web Service Demo</h3>
  <asp:DataGrid id="grid1" runat="server" OnItemCommand="Grid_ItemCommand">
    <Columns>
      <asp:ButtonColumn HeaderText="命令" Text="定购" ButtonType="PushButton" />
      <asp:TemplateColumn HeaderText="数量">
        <ItemTemplate>
          <asp:TextBox id="txtCount" width="30pt" runat="server"/>
        </ItemTemplate>
      </asp:TemplateColumn>
    </Columns>
  </asp:DataGrid>
  <hr/><asp:Label id="Label1" runat="server">已经定购</asp:Label>
  </form>
  </body>
</html>

⌨️ 快捷键说明

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