横着显示一排下拉框 选择 尺寸
左边竖着显示一列下拉框 选择 颜色
中间输入 数量
请问应如何做

解决方案 »

  1.   

    看看我写的代码,是不是这个意思:>>>>Default4.aspx====================<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>無題のページ</title>
        <style type="text/css">
            table{
                border:solid 1px black;
            }
            tr{
                border:solid 1px black;
            }
            td{
                border:solid 1px black;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Table ID="Table1" runat="server">
                <asp:TableFooterRow ID="TableFooterRow1" runat="server">
                    <asp:TableCell ID="TableCell1" runat="server">
                        <span>颜色\尺寸</span>
                    </asp:TableCell>                
                </asp:TableFooterRow>            
            </asp:Table>
        </div>
        </form>
    </body>
    </html>
    >>>>>>>>>>Default4.aspx.cs====================
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Xml;public partial class Default4 : System.Web.UI.Page
    {
        protected string table = "<table><row><cell/><cell sel=\"0\" /></row><row><cell sel=\"0\" /><cell cnt=\"24\" /></row></table>";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState.Add("table", table);
            }
            KeepTable();
        }    protected void SelectColor(object sender, EventArgs e)
        {
            for (int i = 1; i < this.Table1.Rows[0].Cells.Count; i++)
            {
                if (((DropDownList)(this.Table1.Rows[0].Cells[i].Controls[0])).SelectedIndex < 1)
                {
                    return;
                }
            }
            AddRowHeader(0);        TableRow newRow = this.Table1.Rows[this.Table1.Rows.Count - 1];        for (int i = 1; i < this.Table1.Rows[0].Cells.Count; i++)
            {
                TableCell countCell = new TableCell();
                newRow.Cells.Add(countCell);
                TextBox countBox = new TextBox();
                countCell.Controls.Add(countBox);
            }
                 
                    
        }    protected void SelectSize(object sender, EventArgs e)
        {
            for (int i = 1; i < this.Table1.Rows.Count; i++)
            {
                if (((DropDownList)(this.Table1.Rows[i].Cells[0].Controls[0])).SelectedIndex < 1)
                {
                    return;
                }
            }
            AddColumnHeader(0);        for (int i = 1; i < this.Table1.Rows.Count; i++)
            {
                TableCell countCell = new TableCell();
                this.Table1.Rows[i].Cells.Add(countCell);
                TextBox countBox = new TextBox();
                countCell.Controls.Add(countBox);
            }
        }    private void AddRowHeader(int index)
        {
            TableRow newRow = new TableRow();
            this.Table1.Rows.Add(newRow);        TableCell firsCell = new TableCell();
            newRow.Cells.Add(firsCell);        DropDownList colorDrop = new DropDownList();
            ListItem list0 = new ListItem("选择颜色", "0");
            ListItem list1 = new ListItem("red", "red");
            ListItem list2 = new ListItem("green", "green");
            ListItem list3 = new ListItem("blue", "blue");
            colorDrop.Items.Add(list0);
            colorDrop.Items.Add(list1);
            colorDrop.Items.Add(list2);
            colorDrop.Items.Add(list3);
            colorDrop.SelectedIndex = index;
            colorDrop.AutoPostBack = true;
            colorDrop.SelectedIndexChanged += new EventHandler(SelectColor);        firsCell.Controls.Add(colorDrop);        
        }    private void AddColumnHeader(int index)
        {
            TableCell firsCell = new TableCell();
            this.Table1.Rows[0].Cells.Add(firsCell);
            DropDownList sizeDrop = new DropDownList();
            ListItem list0 = new ListItem("选择尺寸", "0");
            ListItem list1 = new ListItem("1", "1");
            ListItem list2 = new ListItem("2", "2");
            ListItem list3 = new ListItem("3", "3");
            sizeDrop.Items.Add(list0);
            sizeDrop.Items.Add(list1);
            sizeDrop.Items.Add(list2);
            sizeDrop.Items.Add(list3);
            sizeDrop.SelectedIndex = index;
            sizeDrop.AutoPostBack = true;
            sizeDrop.SelectedIndexChanged += new EventHandler(SelectSize);
            firsCell.Controls.Add(sizeDrop);
        }
        
        private void KeepTable()
        {
            string str = ViewState["table"].ToString();        XmlDocument doc = new XmlDocument();
            doc.LoadXml(str);        XmlNode table = doc.DocumentElement;        XmlNodeList rows = table.ChildNodes;        for (int i = 1; i < rows.Count; i++)
            {
                AddRowHeader(Convert.ToInt32(rows[i].ChildNodes[0].Attributes[0].Value));
            }        XmlNodeList columns = rows[0].ChildNodes;        for (int i = 1; i < columns.Count; i++)
            {
                AddColumnHeader(Convert.ToInt32(columns[i].Attributes[0].Value));
                for (int j = 1; j < rows.Count; j++)
                {
                    TableCell countCell = new TableCell();
                    this.Table1.Rows[j].Cells.Add(countCell);
                    TextBox countBox = new TextBox();
                    countBox.Text = rows[j].ChildNodes[i].Attributes[0].Value;
                    countCell.Controls.Add(countBox);
                }
            }
        }
    }
      

  2.   

    To:philoo(小毛驴尥蹶子)大概就是这个意思