C# 后台动态生成textbox
2009-11-10 11:11
429 查看
DataTable tablesource=new DataTable();
protected void CheckBoxList2_SelectedIndexChanged(object sender, EventArgs e)
{
Table table = new Table();
TableRow TabRow = new TableRow();
TabRow.HorizontalAlign = HorizontalAlign.Center;
TableCell TabCell = new TableCell();
TabCell.Text = "颜色";
TabRow.Cells.Add(TabCell);
TabCell = new TableCell();
TabCell.Text = "尺码";
TabRow.Cells.Add(TabCell);
TabCell = new TableCell();
TabCell.Text = "单价";
TabRow.Cells.Add(TabCell);
TabCell = new TableCell();
TabCell.Text = "数量";
TabRow.Cells.Add(TabCell);
TabCell = new TableCell();
TabCell.Text = "商家编码";
TabRow.Cells.Add(TabCell);
table.Rows.Add(TabRow);
DataTable tb = tablesource;
Response.Write(tb.Rows.Count.ToString());
int j = 0;
foreach (DataRow Row in tb.Rows)
{
j++;
for (int i = 0; i < this.CheckBoxList2.Items.Count; i++)
{
TabRow = new TableRow();
TabCell = new TableCell();
TabCell.Text = Row["颜色"].ToString();
TabRow.Cells.Add(TabCell);
if (CheckBoxList2.Items[i].Selected)
{
//尺码
TabCell = new TableCell();
TabCell.Text = this.CheckBoxList2.Items[i].Value;
TabRow.Cells.Add(TabCell);
////单价
TabCell = new TableCell();
TextBox txtboxprice = new TextBox();
txtboxprice.ID = "price" + j.ToString() + "-" + i.ToString();
txtboxprice.AutoPostBack = true;
txtboxprice.TextChanged += new EventHandler(txtbox_TextChanged);
TabCell.Controls.Add(txtboxprice);
TabRow.Cells.Add(TabCell);
//数量
TabCell = new TableCell();
TextBox txtboxquantiy = new TextBox();
txtboxquantiy.ID = "quantity" + j.ToString() + "-" + i.ToString();
txtboxquantiy.AutoPostBack = true;
txtboxquantiy.TextChanged += new EventHandler(txtbox_TextChanged);
TabCell.Controls.Add(txtboxquantiy);
TabRow.Cells.Add(TabCell);
////商家编码
TabCell = new TableCell();
TextBox txtboxprice = new TextBox();
txtboxprice.ID = "encode" + j.ToString() + "-" + i.ToString();
txtboxprice.AutoPostBack = true;
txtboxprice.TextChanged += new EventHandler(txtbox_TextChanged);
TabCell.Controls.Add(txtboxprice);
TabRow.Cells.Add(TabCell);
table.Rows.Add(TabRow);
}
}
}
Place3.Controls.Add(table);
}
protected void CheckBoxList2_SelectedIndexChanged(object sender, EventArgs e)
{
Table table = new Table();
TableRow TabRow = new TableRow();
TabRow.HorizontalAlign = HorizontalAlign.Center;
TableCell TabCell = new TableCell();
TabCell.Text = "颜色";
TabRow.Cells.Add(TabCell);
TabCell = new TableCell();
TabCell.Text = "尺码";
TabRow.Cells.Add(TabCell);
TabCell = new TableCell();
TabCell.Text = "单价";
TabRow.Cells.Add(TabCell);
TabCell = new TableCell();
TabCell.Text = "数量";
TabRow.Cells.Add(TabCell);
TabCell = new TableCell();
TabCell.Text = "商家编码";
TabRow.Cells.Add(TabCell);
table.Rows.Add(TabRow);
DataTable tb = tablesource;
Response.Write(tb.Rows.Count.ToString());
int j = 0;
foreach (DataRow Row in tb.Rows)
{
j++;
for (int i = 0; i < this.CheckBoxList2.Items.Count; i++)
{
TabRow = new TableRow();
TabCell = new TableCell();
TabCell.Text = Row["颜色"].ToString();
TabRow.Cells.Add(TabCell);
if (CheckBoxList2.Items[i].Selected)
{
//尺码
TabCell = new TableCell();
TabCell.Text = this.CheckBoxList2.Items[i].Value;
TabRow.Cells.Add(TabCell);
////单价
TabCell = new TableCell();
TextBox txtboxprice = new TextBox();
txtboxprice.ID = "price" + j.ToString() + "-" + i.ToString();
txtboxprice.AutoPostBack = true;
txtboxprice.TextChanged += new EventHandler(txtbox_TextChanged);
TabCell.Controls.Add(txtboxprice);
TabRow.Cells.Add(TabCell);
//数量
TabCell = new TableCell();
TextBox txtboxquantiy = new TextBox();
txtboxquantiy.ID = "quantity" + j.ToString() + "-" + i.ToString();
txtboxquantiy.AutoPostBack = true;
txtboxquantiy.TextChanged += new EventHandler(txtbox_TextChanged);
TabCell.Controls.Add(txtboxquantiy);
TabRow.Cells.Add(TabCell);
////商家编码
TabCell = new TableCell();
TextBox txtboxprice = new TextBox();
txtboxprice.ID = "encode" + j.ToString() + "-" + i.ToString();
txtboxprice.AutoPostBack = true;
txtboxprice.TextChanged += new EventHandler(txtbox_TextChanged);
TabCell.Controls.Add(txtboxprice);
TabRow.Cells.Add(TabCell);
table.Rows.Add(TabRow);
}
}
}
Place3.Controls.Add(table);
}
相关文章推荐
- C#后台动态生成CheckBoxList
- Windows Phone 7使用C#通过后台动态生成Grid网格布局
- C# 动态生成textbox,Combobox等控件
- wp7使用C#通过后台动态生成Grid网格布局
- C# 动态生成的textbox怎样获取值
- C#利用定时任务插件实现在后台线程中批量把动态文件生成静态文件方法
- C#如何遍历动态生成的textbox,Combobox 等控件
- (转)【C#利用后台动态加载数据】Winform“防界面卡死”
- C#动态生成子菜单(以IE收藏夹菜单为例)
- C#也能动态生成Word文档并填充数据
- 如何让C#生成的dll动态库文件,在被引用时带有注释备注提示
- C# 在后台更改TextBox属性 (可编辑或只读,颜色)
- 用C#动态生成Word文档并将数据填入Word表格中
- C#动态生成html页面
- 【C#利用后台动态加载数据】Winform“防界面卡死”
- C#也能动态生成Word文档并填充数据
- C#中"对于多个基表不支持动态SQL生成"的错误原因
- C#动态生成控件以及添加事件处理
- 【ASP.NET】js动态生成的控件,在后台获取不到怎么办?
- 调用后台动态的生成Highcharts图表