Dynamically create checkbox and check if it is checked - ASP>NET
net so my question is, how can I check if the checkbox that I dynamically create is checked? Here is my code for creating the checkbox:
TableCell cell_CheckBox = 开发者_JS百科new TableCell();
CheckBox cbItemOrd = new CheckBox();
cell_CheckBox.Controls.Add(cbItemOrd);
cbList.Add(cbItemOrd);
cell_CheckBox.HorizontalAlign = HorizontalAlign.Left;
cell_CheckBox.VerticalAlign = VerticalAlign.Top;
tr.Cells.Add(cell_CheckBox);
tblSelectedCatItems.Rows.Add(tr);
Give your checkbox an ID and use FindControl to retrieve it.
CheckBox cbItemOrd = new CheckBox();
cbItemOrd.ID="yourID";
You can use cbItemOrd.Checked property to test it's state.
CheckBox cbItemOrd=Page.FindControl("yourID") as CheckBox;
if(cbItemOrd.Checked)
{
...do something
}
Find the control do stuff...
CheckBox cbItemOrd = (CheckBox) Page.FindControl(cbItemOrdId);
if(cbItemOrd.Checked)
...do something
CheckBoxList objlst = new CheckBoxList();
//create checkbox list at run time
lst.Items.Add("iteam_name");
// add items in that
lst.Items[0].Selected == true;
// items is selected then it is true.
精彩评论