Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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++;
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.DataBind();
LiteralControl lineBreak = new LiteralControl("
");
PlaceholderSku.Controls.Add(Cb);
PlaceholderSku.Controls.Add(lineBreak);


}
}

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;


LiteralControl lineBreak = new LiteralControl("
");
PlaceholderSku.Controls.Add(Cb);
PlaceholderSku.Controls.Add(lineBreak);
controlIdList.Add(Cb.ID);
ViewState["controlIdList"] = controlIdList;//storing ids

}
Posted

1 solution

You don't add a click handler when you create the object:
C#
Cb.Attributes.Add("runat", "server");
Cb.DataBind();
Cb.Click += new EventHandler(btnAddSku_Click);
Might help.
 
Share this answer
 
Comments
mrDivan 18-Feb-14 6:41am    
Thanks but it didnt work
OriginalGriff 18-Feb-14 7:28am    
What did happen? Did it get into the click handler? Did you check? How?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900