Checkbox has the wrong values
Posted
by Praesagus
on Stack Overflow
See other posts from Stack Overflow
or by Praesagus
Published on 2010-04-26T22:56:18Z
Indexed on
2010/04/27
16:53 UTC
Read the original article
Hit count: 397
I have a page with several checkboxes on it, along with a dropdownlist of users.
The checkboxes correlate to the user's permissions so each user is different.
When a different user is chosen, the check boxes should change to match that user's permissions.
The codebehind is correct, I stepped through it and the checkbox.checked
value is being assigned to the box with the correct value to match the user. chk.Checked = viewable;
No matter what I assign to the checked property the value stays the same as the very first submittal.
I tried chk.EnableViewState = false;
but that did not help. I am sure it is dot net trying to be helpful (grrr).
Thank you for your help.
There is no databinding per se. I will be saving the values from the textboxes via xmlhttp when the user clicks on them. I never want the check boxes to fill with values other than what I give them. Here is the essence of the code.
foreach (DataRow dRow in dTable.Rows)
{
viewable = Convert.ToBoolean(dRow["Viewable"]);
table.Rows.Add(CreatePageRow(Convert.ToString(dRow["SitePageViewName"]), Convert.ToString(dRow["SitePageName"]), folderDepth, maxFolderDepth, viewable));
}
FileTree.Controls.Add(table);
private TableRow CreatePageRow(String ViewName, String FileName, Int32 folderDepth, Int32 maxFolderDepth, Boolean viewable)
{
TableRow tr = new TableRow();
tr.Cells.Add(CreateCheckboxCell(viewable, folderDepth+3));
tr.Cells.Add(CreateImageCell("/images/icon/sm/report_graph.gif", "Page: " + ViewName));
tr.Cells.Add(CreateTitleCell(ViewName, maxFolderDepth - (folderDepth+1), FileName));
return tr;
}
private TableCell CreateCheckboxCell(Boolean viewable, Int32 colSpan)
{
TableCell td = new TableCell();
if (colSpan > 1) td.ColumnSpan = colSpan;
CheckBox chk = new CheckBox();
chk.Checked = viewable;
chk.EnableViewState = false;
td.Controls.Add(chk);
td.CssClass = "right";
return td;
}
© Stack Overflow or respective owner