如何在占位符存储在列表中时添加控件 [英] How to add controls to placeholder when they are stored in a list
本文介绍了如何在占位符存储在列表中时添加控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我保存在列表中单击按钮时创建的控件。然后在loadviewstate上创建它们,但我无法弄清楚如何在占位符的一行中创建控件。我不希望它在一条线上创建一个控件。所以在foreach循环中,我必须将两个控件添加到占位符中的同一行,但我似乎无法弄清楚任何帮助将不胜感激。
I save the controls that are created on button click in an list. The and then create them on loadviewstate but i Cannot figure out how to create the controls in one line in the place holder. I dont want it to create a control on a line. So in the foreach loop the both controls must me added to the same line in the placeholder but I cant seem to figure it out any help would be appreciated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxEditors;
public partial class test : System.Web.UI.Page
{
List<string> controlIdList = new List<string>();//to store control Id on each postback
int counter = 0;//count Number of Comboboxes
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
controlIdList = (List<string>)ViewState["controlIdList"];
Table tb = new Table();
TableRow tr = new TableRow();
TableCell tc = new TableCell();
TableCell tc2 = new TableCell();
foreach (string id in controlIdList)
{
counter++;
ASPxComboBox Cb = new ASPxComboBox();
Cb.ID = id;
Cb.DataSource = sdSku;
Cb.TextField = "SkU";
Cb.ValueField = "SkU";
Cb.ValueType = typeof(string);
Cb.Columns.Add("SKU");
Cb.Columns.Add("Model");
Cb.Columns.Add("Name");
Cb.Attributes.Add("runat", "server");
Cb.DataSource = sdSku;
Cb.DataBind();
// PlaceholderSku.Controls.Add(Cb);
// PlaceholderSku.Controls.Add(new LiteralControl("<br/>"));
tc2.Controls.Add(Cb);
tr.Cells.Add(tc2);
tb.Rows.Add(tr);
ASPxLabel Lb = new ASPxLabel();
Lb.Text = "Select SKU";
Lb.ID = id;
//PlaceholderSku.Controls.Add(Lb);
tc.Controls.Add(Lb);
tr.Cells.Add(tc);
tb.Controls.Add(tr); tb.ID = "table" + counter;
}
PlaceholderSku.Controls.Add(tb);
PlaceholderSku.Controls.Add(new LiteralControl("<br/>"));
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAddSku_Click(object sender, EventArgs e)
{
counter++;
ASPxComboBox Cb = new ASPxComboBox();
Cb.ID = "SkuComboBox" + counter;
ASPxLabel Lb = new ASPxLabel();
Lb.ID = "label" + counter;
controlIdList.Add(Lb.ID);
controlIdList.Add(Cb.ID);
ViewState["controlIdList"] = controlIdList;//storing ids
}
}
- 编辑:已删除呼叫,使用预标签格式化的代码块
-- shouting removed, code block formatted with pre tags
推荐答案
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxEditors;
public partial class eOPS_Orders_FNB_Stock_PurchaseOrder : System.Web.UI.Page
{
List<string> controlIdList = new List<string>();//to store control Id on each postback
int counter = 0;//count Number of Comboboxes
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
controlIdList = (List<string>)ViewState["controlIdList"];
foreach (string id in controlIdList)
{
counter++;
//create new Combobox
ASPxComboBox Cb = new ASPxComboBox();
Cb.ID = "SkuComboBox" + counter;
Cb.DataSource = sdSku;
Cb.TextField = "SkU";
Cb.ValueField = "SkU";
Cb.ValueType = typeof(string);
Cb.Columns.Add("SKU");
Cb.Columns.Add("Model");
Cb.Columns.Add("Name");
Cb.Attributes.Add("runat", "server");
Cb.DataSource = sdSku;
Cb.DataBind();
//create new Label
ASPxLabel Lb = new ASPxLabel();
Lb.Text = "Select SKU";
Lb.ID = "Label"+counter;
//Create new Table add the above created controls to the table
Table tb = new Table();
TableRow tr = new TableRow();
TableCell tc = new TableCell();
TableCell tc2 = new TableCell();
tc.Controls.Add(Lb);
tr.Cells.Add(tc);
tb.Controls.Add(tr);
tb.ID = id;
tc2.Controls.Add(Cb);
tr.Cells.Add(tc2);
tb.Rows.Add(tr);
//add table to the Pade
PlaceholderSku.Controls.Add(tb);
PlaceholderSku.Controls.Add(new LiteralControl("<br/>"));
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAddSku_Click(object sender, EventArgs e)
{
counter++;
Table tb = new Table();
tb.ID = "Table" + counter;
controlIdList.Add(tb.ID);
ViewState["controlIdList"] = controlIdList;//storing ids
}
}
这篇关于如何在占位符存储在列表中时添加控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文