Hi all, I'm currently stuck with a simple problem, which I cannot seem to get it to work for the past few days.
I'm trying to get the CheckBox type from a ControlCollection but it don't seem to work regardless of how I been trying it...
The checkboxes are created based on the number of records returned from my dataset...
I'm currently clueless as to how I should go about solving this problem...
TypeScript
protectedvoidsubCheckAll(object sender, EventArgs e)
{
checkAllHTML(this, ((CheckBox)sender).Checked);
}
// This is the Event of the CheckBox
C#
privatevoidcheckAllHTML(Control parent, bool blnChecked)
{
string sParentTest = parent.Controls.GetType().ToString();
string sParentTest2 = parent.GetType().ToString();
//string sParentTest3 = Parent.Controls.GetType().ToString();foreach (Control child in parent.Controls)
{
if (child is CheckBox)
{
CheckBox chk = (CheckBox)child;
chk.Checked = blnChecked;
//((CheckBox)child).Checked = blnChecked;
}
if ((child.Controls.Count > 0))
{
checkAllHTML(child, blnChecked);
}
}
} // Error - Control child is always LiteralControl // I tried casting it as a checkbox but it don't work as well...
Java
privatevoidCreateCheck()
{
//Put user code to initialize the page hereCheckBoxchkBox=newCheckBox();
inti=0;
DataSetds=newDataSet();
intlintHeadID=0;
stringlstrGroup= string.Empty;
boollblFisrt=false;
ds = CreateDataSource();
lstrGroup = "";
lblFisrt = false;
lintHeadID = 0;
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
if (lstrGroup != ds.Tables[0].Rows[i][3].ToString()) // Rows[i][3] <-- The [3] The 3rd Column in the Table
{
lintHeadID = lintHeadID + 1;
lstrGroup = (string)ds.Tables[0].Rows[i][3];
stringsHeaderID= lintHeadID + "00";
chkBox.ID = String.Format(sHeaderID) + "chkHeader" + i;
//chkBox.ID = Strings.Format(lintHeadID, "00") + "chkHeader" + i;
chkBox.Text = lstrGroup;
chkBox.Font.Bold = true;
chkBox.Font.Name = "Verdana";
chkBox.Font.Size = FontUnit.XSmall;
chkBox.Width = Unit.Percentage(100);
chkBox.BackColor = Color.SkyBlue;
chkBox.Font.Underline = true;
TableRowtr1=newTableRow();
TableCelltd3=newTableCell();
TableCelltd1=newTableCell();
td3.Width = Unit.Percentage(5);
tr1.Cells.Add(td3);
td1.Controls.Add(chkBox);
tr1.Cells.Add(td1);
lblFisrt = !lblFisrt;
if (lblFisrt)
{
tblPermission.Rows.Add(tr1);
}
else
{
tblPermission2.Rows.Add(tr1);
}
chkBox.AutoPostBack = true;
chkBox.CheckedChanged += Master_CheckedChanged;
}
chkBox = newCheckBox();
stringsHeadID= lintHeadID + "00";
chkBox.ID = String.Format(sHeadID) + "chkDetail" + i;
chkBox.Text = (string)ds.Tables[0].Rows[i][1];
chkBox.ToolTip = (string)ds.Tables[0].Rows[i][0];
//store permission id in tooptipTableRowtr=newTableRow();
TableCelltd=newTableCell();
TableCelltd2=newTableCell();
td2.Width = Unit.Percentage(5);
tr.Cells.Add(td2);
td.Controls.Add(chkBox);
tr.Cells.Add(td);
chkBox.CheckedChanged += Detail_CheckedChanged;
if (lblFisrt)
{
tblPermission.Rows.Add(tr);
}
else
{
tblPermission2.Rows.Add(tr);
}
}
} // I create the checkboxes based on the results returned from my Dataset
I really would appreciate for any assistance on this problem... I been trying other ways but just can't seem to get the child control as a checkbox based on the parent...
Thanks alot in advance
Hubert
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
rajesh p vRank #7,584 · 238 reputationPosted Dec 12, 2009, 9:02 AM EST