I programmatically add checkboxes to ASP.NET WebForm. I want to iterate through Request.Form.Keys and get the value of the flags. ASP.NET flags do not have a value attribute.
How to set the value attribute so that when iterating through Request.Form.Keys, I get a more meaningful value than the default value of "on".
Code for adding checkboxes to the page:
List<string> userApps = GetUserApplications(Context); Panel pnl = new Panel(); int index = 0; foreach (BTApplication application in Userapps) { Panel newPanel = new Panel(); CheckBox newCheckBox = new CheckBox(); newPanel.CssClass = "filterCheckbox"; newCheckBox.ID = "appSetting" + index.ToString(); newCheckBox.Text = application.Name; if (userApps.Contains(application.Name)) { newCheckBox.Checked = true; } newPanel.Controls.Add(newCheckBox); pnl.Controls.Add(newPanel); index++; } Panel appPanel = FindControlRecursive(this.FormViewAddRecordPanel, "applicationSettingsPanel") as Panel; appPanel.Controls.Add(pnl);
Code for getting flag values ββfrom Request.Form:
StringBuilder settingsValue = new StringBuilder(); foreach (string key in Request.Form.Keys) { if (key.Contains("appSetting")) { settingsValue.Append(","); settingsValue.Append(Request.Form[key]); } }
M. Travis Volker
source share