Add value attribute to ASP.NET Checkbox

zelimxan

New Member
I'm programmatically adding checkboxes to a ASP.NET WebForm. I want to iterate through the Request.Form.Keys and get the value of the checkboxes. ASP.NET Checkboxes don't have a value attribute.How do I set the value attribute so that when I iterate through the Request.Form.Keys I get a more meaningful value than the default "on".Code for adding the checkboxes to the page:\[code\]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\]Code for retrieving checkbox values from Request.Form:\[code\]StringBuilder settingsValue = http://stackoverflow.com/questions/13733120/new StringBuilder();foreach (string key in Request.Form.Keys){ if (key.Contains("appSetting")) { settingsValue.Append(","); settingsValue.Append(Request.Form[key]); }}\[/code\]
 
Back
Top