I'm looking for assistance with overcoming an issue I have been having with an asp.net web application for the past 6 weeks. Any assistance would be tremendously beneficial.
The web application I’m working on will ultimately reset Sybase accounts across 30+ database instances. The current layout of the application is as follows:
- User prompted for Sybase account
- Goes through list of databases and check if user as access to the instance
- If user has access; application builds a panel of dynamically created checkbox.
Up to this point I have working. Below is what I need help on.
- Once the methods above loops through the db’s and builds the checkbox; I need create the ability for a user to select one or many of the dynamically created checkbox and pass the value, id, name or any identify element of the control to a reset password method.
Below is the code I’m working with that does not work:
foreach (object o in envPnl2.Controls)
{
CheckBox chk = o as CheckBox;
if (chk == null)
continue;
if (chk.Checked)
{
resetPassword(chk.Text);
}
}
Below is the code I’m using to create the checkbox and add them to a table (for alignment):
void createDynChks(int c, string db)
{
TableRow tr = new TableRow();
// Create column 1
TableCell td1 = new TableCell();
// Create a checkbox control dynamically
CheckBox _checkbox = new CheckBox();
_checkbox.ID = db;
_checkbox.Text = db;
if ((c == 2) || (c == 4))
{
_checkbox.Enabled = false;
}
// Add control to the table cell
td1.Controls.Add(_checkbox);
// Add cell to the row
tr.Cells.Add(td1);
tr.HorizontalAlign = HorizontalAlign.Left;
// Add row to the table.
if (cntclmn == 1)
{
tblDyn1.Rows.Add(tr);
}
if (cntclmn == 2)
{
tblDyn2.Rows.Add(tr);
}
if (cntclmn == 3)
{
tblDyn3.Rows.Add(tr);
}
if (cntclmn == 4)
{
tblDyn4.Rows.Add(tr);
}
if (cntclmn == 5)
{
tblDyn5.Rows.Add(tr);
}
}
Please help if anyone can offer a direction.
-Dan
Daniel ScalfaroPosted Jun 4, 2007, 4:00 PM
-Dan
Jan MontanoPosted Jun 1, 2007, 12:02 AM
tblDyn1?->TableRow->TableCell->CheckBox
tblDyn2?->TableRow->TableCell->CheckBox
tblDyn3?->TableRow->TableCell->CheckBox
tblDyn4?->TableRow->TableCell->CheckBox
tblDyn5?->TableRow->TableCell->CheckBox
What is tblDyn1,2,3,4,5? Is this contained inside your panel?
Daniel ScalfaroPosted May 31, 2007, 4:29 PM
Thanks for the reply.. The foreach loop does not recognize any checkbox controls in the panel. If I add them in manually it does, but not if I create them after build time.
Hope that clarifies.
Thanks
-Dan
Jan MontanoPosted May 31, 2007, 6:45 AM