日期:2014-05-17  浏览次数:20413 次

table不能维持数据的问题
我写的下单页面PlaceOrder.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="PlaceOrder.aspx.cs" Inherits="PlaceOrder" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h2>下单页面:</h2>
 产品列表:
    
    <asp:GridView ID="GridView2" ......>
    <asp:SqlDataSource .......>   
        已经选择的产品:<br />

        <asp:Table ID="items" runat="server" EnableViewState="true">
        </asp:Table>
      
        <br />
        <asp:Button ID="Button1" runat="server" Text="提交" />
        <br />
</asp:Content>

后台代码:
public partial class PlaceOrder : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {
        string productInfoId = GridView2.SelectedRow.Cells[0].Text.Trim();
        string productName = GridView2.SelectedRow.Cells[1].Text.Trim();
  
        items.Rows.Add(getNewRow(productInfoId, productName));

    }

    private TableRow getNewRow(string productInfoId,string productName )
    {
        TableRow tr = new TableRow();
        tr.BorderWidth = 1;
        //1
        TableCell tc = new TableCell();
        tc.Visible = false;
        tc.Text = productInfoId;
        tr.Cells.Add(tc);
        //2
        tc = new TableCell();
        tc.Width = 150;
        tc.Text = productName;
        tr.Cells.Add(tc);
        //3
        tc = new TableCell();
        tc.Width = 70;
        TextBox tb = new TextBox();
        tb.Width = 30;
        tc.Controls.Add(tb);
        Label