Checkboxes from Code-behind

Shurikn

Regular
Joined
Jul 14, 2004
Messages
62
hello I'm haveing a stupid problem with checkbox/radio button, I am creating a whole page from code behind, the page is is actually displaying a database, and on every row, the first collon is a check box, but since the row is created in code-behind, so is the checkbox, and I am unable to acess this comtrol after... So In the header i put a check box to chek all the other check box under them (like in hotmail) but it just wont work since it does not see the other check boxes... herse my check box code:

Code:
private void chkAll_ServerClick(object sender, System.EventArgs e)
{
	if(chkAll.Checked)
	{
		foreach (Control objC in Page.Controls)
		{
			Type objType = objC.GetType();
			if (objType.FullName == "System.Web.UI.HtmlControls.HtmlForm")
			{
				HtmlForm objF = (HtmlForm) objC;
				foreach (Control objWC in objF.Controls)
				{
					Type objWCType = objWC.GetType();
					if (objWCType.FullName == "System.Web.UI.HtmlControls.HtmlInputCheckBox")
					{
						CheckBox objCB = (CheckBox) objWC;
						objCB.Checked = true;
					}
				}
			}
		}
	}
	else
	{
		foreach (Control objC in Page.Controls)
		{
			Type objType = objC.GetType();
			if (objType.FullName == "System.Web.UI.HtmlControls.HtmlForm")
			{
				HtmlForm objF = (HtmlForm) objC;
				foreach (Control objWC in objF.Controls)
				{
					Type objWCType = objWC.GetType();
					if (objWCType.FullName == "System.Web.UI.HtmlControls.HtmlInputCheckBox")
					{
						CheckBox objCB = (CheckBox) objWC;
						objCB.Checked = false;
					}
				}
			}
		}
	}
}

I am having the same problem in another page, the other page is a page that controls acess to a certain folders, you can chose groups or members and add thgem to the list then set them rights... i wanted to do this with check boxes, (CHMOD style) 9 check boxes for each group/member 3 columns, 3 row, row1= view, row2=download, row3= upload/delete
column1= own, colum2= group, column3 = all

once again... same problem, if i want to add a group/member i have to do it trough code... and once again I will not be able to chek the status of my checkboxes.

please help!!!
 
Are the checkboxes in a DataGrid? You should be able to use the FindControl function to get access to each of the checkboxes.
Code:
CType(dgDataGrid.FindControl("chkCheckBox"), CheckBox).Checked
I think there's a FindControl for the Page object too.

I hope this at least get's you pointed in the right direction. :)
Good Luck!
 
Back
Top