#region //尺寸选择DimensionChanged
protected void ddl_item_dimension_SelectedIndexChanged(object sender, EventArgs e)
{
Function fc = new Function();
if (fc.IsNumberic(ddl_item_dimension.SelectedValue.ToString()))
{
int dtype = Convert.ToInt32(this.ddl_item_dimension.SelectedValue);
TableRow tRow1 = new TableRow();
TableCell tCell1 = new TableCell();
TableCell tCell2 = new TableCell();
Table1.Rows.Add(tRow1);
tRow1.BackColor = Color.LightGray;
tCell1.Controls.Add(new LiteralControl("NO."));
tCell1.HorizontalAlign = HorizontalAlign.Center;
tCell1.BackColor = Color.LightGray;
tRow1.Cells.Add(tCell1); tCell2.Controls.Add(new LiteralControl("Multi-Dimensions"));
tCell2.HorizontalAlign = HorizontalAlign.Center;
tRow1.Cells.Add(tCell2);
for (int i = 0; i < dtype; i++)
{
TableRow tRow = new TableRow();
TableCell tCell = new TableCell(); Table1.Rows.Add(tRow);
tCell.Controls.Add(new LiteralControl((i+1)+"."));
tCell.HorizontalAlign = HorizontalAlign.Center;
if (i % 2 == 0)
{
tCell.BackColor = Color.WhiteSmoke;
}
else
{
tCell.BackColor = Color.LightGray;
}
tRow.Cells.Add(tCell);
//
TableCell tCellT = new TableCell();
// tCellT.HorizontalAlign = HorizontalAlign.Center;
tCellT.Width = Unit.Parse("90%");
if (i % 2 == 0)
{
tCellT.BackColor = Color.WhiteSmoke;
}
else
{
tCellT.BackColor = Color.LightGray;
}
tCellT.Controls.Add(new LiteralControl("L:"));
System.Web.UI.WebControls.TextBox tBoxL = new TextBox();
tBoxL.Width = Unit.Parse("30px");
tBoxL.ID = "L" + i;
tBoxL.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tCellT.Controls.Add(tBoxL);
tCellT.Controls.Add(new LiteralControl(" "));
tCellT.Controls.Add(new LiteralControl("W:"));
System.Web.UI.WebControls.TextBox tBoxW = new TextBox();
tBoxW.Width = Unit.Parse("30px");
tBoxW.ID = "W" + i;
tBoxW.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tCellT.Controls.Add(tBoxW);
tCellT.Controls.Add(new LiteralControl(" ")); tCellT.Controls.Add(new LiteralControl("H:"));
System.Web.UI.WebControls.TextBox tBoxH = new TextBox();
tBoxH.Width = Unit.Parse("30px");
tBoxH.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tBoxH.ID = "H" + i;
tCellT.Controls.Add(tBoxH);
tCellT.Controls.Add(new LiteralControl(" ")); tCellT.Controls.Add(new LiteralControl("X:"));
System.Web.UI.WebControls.TextBox tBoxX = new TextBox();
tBoxX.Width = Unit.Parse("30px");
tBoxX.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tBoxX.ID = "X" + i;
tCellT.Controls.Add(tBoxX);
tCellT.Controls.Add(new LiteralControl(" "));
//
tRow.Cells.Add(tCellT); //
} }
else { }
}
#endregion我这样动态生成一个表格,表格里放了textbox,我怎样在提交的时候得到这些textbox的值呢.??
protected void ddl_item_dimension_SelectedIndexChanged(object sender, EventArgs e)
{
Function fc = new Function();
if (fc.IsNumberic(ddl_item_dimension.SelectedValue.ToString()))
{
int dtype = Convert.ToInt32(this.ddl_item_dimension.SelectedValue);
TableRow tRow1 = new TableRow();
TableCell tCell1 = new TableCell();
TableCell tCell2 = new TableCell();
Table1.Rows.Add(tRow1);
tRow1.BackColor = Color.LightGray;
tCell1.Controls.Add(new LiteralControl("NO."));
tCell1.HorizontalAlign = HorizontalAlign.Center;
tCell1.BackColor = Color.LightGray;
tRow1.Cells.Add(tCell1); tCell2.Controls.Add(new LiteralControl("Multi-Dimensions"));
tCell2.HorizontalAlign = HorizontalAlign.Center;
tRow1.Cells.Add(tCell2);
for (int i = 0; i < dtype; i++)
{
TableRow tRow = new TableRow();
TableCell tCell = new TableCell(); Table1.Rows.Add(tRow);
tCell.Controls.Add(new LiteralControl((i+1)+"."));
tCell.HorizontalAlign = HorizontalAlign.Center;
if (i % 2 == 0)
{
tCell.BackColor = Color.WhiteSmoke;
}
else
{
tCell.BackColor = Color.LightGray;
}
tRow.Cells.Add(tCell);
//
TableCell tCellT = new TableCell();
// tCellT.HorizontalAlign = HorizontalAlign.Center;
tCellT.Width = Unit.Parse("90%");
if (i % 2 == 0)
{
tCellT.BackColor = Color.WhiteSmoke;
}
else
{
tCellT.BackColor = Color.LightGray;
}
tCellT.Controls.Add(new LiteralControl("L:"));
System.Web.UI.WebControls.TextBox tBoxL = new TextBox();
tBoxL.Width = Unit.Parse("30px");
tBoxL.ID = "L" + i;
tBoxL.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tCellT.Controls.Add(tBoxL);
tCellT.Controls.Add(new LiteralControl(" "));
tCellT.Controls.Add(new LiteralControl("W:"));
System.Web.UI.WebControls.TextBox tBoxW = new TextBox();
tBoxW.Width = Unit.Parse("30px");
tBoxW.ID = "W" + i;
tBoxW.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tCellT.Controls.Add(tBoxW);
tCellT.Controls.Add(new LiteralControl(" ")); tCellT.Controls.Add(new LiteralControl("H:"));
System.Web.UI.WebControls.TextBox tBoxH = new TextBox();
tBoxH.Width = Unit.Parse("30px");
tBoxH.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tBoxH.ID = "H" + i;
tCellT.Controls.Add(tBoxH);
tCellT.Controls.Add(new LiteralControl(" ")); tCellT.Controls.Add(new LiteralControl("X:"));
System.Web.UI.WebControls.TextBox tBoxX = new TextBox();
tBoxX.Width = Unit.Parse("30px");
tBoxX.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tBoxX.ID = "X" + i;
tCellT.Controls.Add(tBoxX);
tCellT.Controls.Add(new LiteralControl(" "));
//
tRow.Cells.Add(tCellT); //
} }
else { }
}
#endregion我这样动态生成一个表格,表格里放了textbox,我怎样在提交的时候得到这些textbox的值呢.??
TextBox tb=null;
string strValue="";
for (int i = 0; i < dtype; i++)
{
strName="L"+i.ToString();
tb=Page.FindControl(strName) as TextBox;
strValue+=tb.Text+",";
}
default2.aspx:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddl_item_dimension" runat="server" ValidationGroup="shipment" AutoPostBack="True" OnSelectedIndexChanged="ddl_item_dimension_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="0">Dimension Type</asp:ListItem>
<asp:ListItem Value="1">1 Type of Packing</asp:ListItem>
<asp:ListItem Value="2">2 Type of Packing</asp:ListItem>
<asp:ListItem Value="3">3 Type of Packing</asp:ListItem>
<asp:ListItem Value="4">4 Type of Packing</asp:ListItem>
<asp:ListItem Value="5">5 Type of Packing</asp:ListItem>
<asp:ListItem Value="6">6 Type of Packing</asp:ListItem>
<asp:ListItem Value="7">7 Type of Packing</asp:ListItem>
<asp:ListItem Value="8">8 Type of Packing</asp:ListItem>
<asp:ListItem Value="9">9 Type of Packing</asp:ListItem>
</asp:DropDownList>
<asp:Table ID="Table1" runat=server></asp:Table>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>default2.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.Drawing;public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
#region //尺寸选择DimensionChanged
protected void ddl_item_dimension_SelectedIndexChanged(object sender, EventArgs e)
{
Function fc = new Function();
if (fc.IsNumberic(ddl_item_dimension.SelectedValue.ToString()))
{
int dtype = Convert.ToInt32(this.ddl_item_dimension.SelectedValue);
TableRow tRow1 = new TableRow();
TableCell tCell1 = new TableCell();
TableCell tCell2 = new TableCell();
Table1.Rows.Add(tRow1);
tRow1.BackColor = Color.LightGray;
tCell1.Controls.Add(new LiteralControl("NO."));
tCell1.HorizontalAlign = HorizontalAlign.Center;
tCell1.BackColor = Color.LightGray;
tRow1.Cells.Add(tCell1); tCell2.Controls.Add(new LiteralControl("Multi-Dimensions"));
tCell2.HorizontalAlign = HorizontalAlign.Center;
tRow1.Cells.Add(tCell2);
for (int i = 0; i < dtype; i++)
{
TableRow tRow = new TableRow();
TableCell tCell = new TableCell(); Table1.Rows.Add(tRow);
tCell.Controls.Add(new LiteralControl((i + 1) + "."));
tCell.HorizontalAlign = HorizontalAlign.Center;
if (i % 2 == 0)
{
tCell.BackColor = Color.WhiteSmoke;
}
else
{
tCell.BackColor = Color.LightGray;
}
tRow.Cells.Add(tCell);
//
TableCell tCellT = new TableCell();
// tCellT.HorizontalAlign = HorizontalAlign.Center;
tCellT.Width = Unit.Parse("90%");
if (i % 2 == 0)
{
tCellT.BackColor = Color.WhiteSmoke;
}
else
{
tCellT.BackColor = Color.LightGray;
}
tCellT.Controls.Add(new LiteralControl("L:"));
System.Web.UI.WebControls.TextBox tBoxL = new TextBox();
tBoxL.Width = Unit.Parse("30px");
tBoxL.ID = "L" + i;
tBoxL.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tCellT.Controls.Add(tBoxL);
tCellT.Controls.Add(new LiteralControl(" "));
tCellT.Controls.Add(new LiteralControl("W:"));
System.Web.UI.WebControls.TextBox tBoxW = new TextBox();
tBoxW.Width = Unit.Parse("30px");
tBoxW.ID = "W" + i;
tBoxW.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tCellT.Controls.Add(tBoxW);
tCellT.Controls.Add(new LiteralControl(" ")); tCellT.Controls.Add(new LiteralControl("H:"));
System.Web.UI.WebControls.TextBox tBoxH = new TextBox();
tBoxH.Width = Unit.Parse("30px");
tBoxH.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tBoxH.ID = "H" + i;
tCellT.Controls.Add(tBoxH);
tCellT.Controls.Add(new LiteralControl(" ")); tCellT.Controls.Add(new LiteralControl("X:"));
System.Web.UI.WebControls.TextBox tBoxX = new TextBox();
tBoxX.Width = Unit.Parse("30px");
tBoxX.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tBoxX.ID = "X" + i;
tCellT.Controls.Add(tBoxX);
tCellT.Controls.Add(new LiteralControl(" "));
//
tRow.Cells.Add(tCellT); //
} }
else { }
}
#endregion protected void Button1_Click(object sender, EventArgs e)
{
string strName = "";
TextBox tb = null;
string strValue = "";
for (int i = 0; i < Convert.ToInt32(this.ddl_item_dimension.SelectedItem.Value.ToString()); i++)
{
strName = "L" + i.ToString();
//tb = (TextBox)Table1.Rows[i+1].Cells[i+1].FindControl(strName);
tb = Page.FindControl(strName) as TextBox;
strValue += tb.Text + ",";
} Response.Write(strValue);
}
}
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.Drawing;public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if (ddl_item_dimension.SelectedValue.ToString() != "")
{
int dtype = Convert.ToInt32(this.ddl_item_dimension.SelectedValue);
TableRow tRow1 = new TableRow();
TableCell tCell1 = new TableCell();
TableCell tCell2 = new TableCell();
Table1.Rows.Add(tRow1);
tRow1.BackColor = Color.LightGray;
tCell1.Controls.Add(new LiteralControl("NO."));
tCell1.HorizontalAlign = HorizontalAlign.Center;
tCell1.BackColor = Color.LightGray;
tRow1.Cells.Add(tCell1); tCell2.Controls.Add(new LiteralControl("Multi-Dimensions"));
tCell2.HorizontalAlign = HorizontalAlign.Center;
tRow1.Cells.Add(tCell2);
for (int i = 0; i < dtype; i++)
{
TableRow tRow = new TableRow();
TableCell tCell = new TableCell(); Table1.Rows.Add(tRow);
tCell.Controls.Add(new LiteralControl((i + 1) + "."));
tCell.HorizontalAlign = HorizontalAlign.Center;
if (i % 2 == 0)
{
tCell.BackColor = Color.WhiteSmoke;
}
else
{
tCell.BackColor = Color.LightGray;
}
tRow.Cells.Add(tCell);
//
TableCell tCellT = new TableCell();
// tCellT.HorizontalAlign = HorizontalAlign.Center;
tCellT.Width = Unit.Parse("90%");
if (i % 2 == 0)
{
tCellT.BackColor = Color.WhiteSmoke;
}
else
{
tCellT.BackColor = Color.LightGray;
}
tCellT.Controls.Add(new LiteralControl("L:"));
System.Web.UI.WebControls.TextBox tBoxL = new TextBox();
tBoxL.Width = Unit.Parse("30px");
tBoxL.ID = "L" + i;
tBoxL.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tCellT.Controls.Add(tBoxL);
tCellT.Controls.Add(new LiteralControl(" "));
tCellT.Controls.Add(new LiteralControl("W:"));
System.Web.UI.WebControls.TextBox tBoxW = new TextBox();
tBoxW.Width = Unit.Parse("30px");
tBoxW.ID = "W" + i;
tBoxW.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tCellT.Controls.Add(tBoxW);
tCellT.Controls.Add(new LiteralControl(" ")); tCellT.Controls.Add(new LiteralControl("H:"));
System.Web.UI.WebControls.TextBox tBoxH = new TextBox();
tBoxH.Width = Unit.Parse("30px");
tBoxH.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tBoxH.ID = "H" + i;
tCellT.Controls.Add(tBoxH);
tCellT.Controls.Add(new LiteralControl(" ")); tCellT.Controls.Add(new LiteralControl("X:"));
System.Web.UI.WebControls.TextBox tBoxX = new TextBox();
tBoxX.Width = Unit.Parse("30px");
tBoxX.ToolTip = "International Volume weight =Inch: L*W*H/166 (LB) CM: L*W*H/6000(Kg) ,Domestic Volume weight =Inch: L*W*H/194 (LB)";
tBoxX.ID = "X" + i;
tCellT.Controls.Add(tBoxX);
tCellT.Controls.Add(new LiteralControl(" "));
//
tRow.Cells.Add(tCellT); //
}
}
else { }
} }
#region //尺寸选择DimensionChanged
protected void ddl_item_dimension_SelectedIndexChanged(object sender, EventArgs e)
{
//Function fc = new Function(); }
#endregion protected void Button1_Click(object sender, EventArgs e)
{
string strName = "";
TextBox tb = null;
string strValue = "";
for (int i = 0; i < Convert.ToInt32(this.ddl_item_dimension.SelectedItem.Value.ToString()); i++)
{
strName = "L" + i.ToString();
tb = (TextBox)Table1.Rows[i+1].Cells[1].FindControl(strName);
//tb = Page.FindControl(strName) as TextBox;
strValue += tb.Text + ",";
} Response.Write(strValue);
}
}=====================================================
The CodeGear.cn 你身边的开发资源
{
string strName = "";
TextBox tb = null;
string strValue = "";
for (int i = 0; i < Convert.ToInt32(this.ddl_item_dimension.SelectedItem.Value.ToString()); i++)
{
strName = "L" + i.ToString();
//tb = (TextBox)Table1.Rows[i+1].Cells[i+1].FindControl(strName);
//tb = Page.FindControl(strName) as TextBox;
//strValue += tb.Text + ",";
strValue += Request[strName].ToString();
} Response.Write(strValue);