我已经从复选框列表中动态创建了复选框,并将此列表保存到会话中,并希望在复选框的 onChange 事件中从会话中获取此复选框列表。这是代码。
public static List <CheckBox> chklist = new List <CheckBox> ();
void arrinit() {
for (int i = 0; i < 31; i++) {
//initializing list of checkboxes
chklist.Add(new CheckBox());
}
}
void show() {
for (int i = 0; i < 30; i++) {
TableCell cell4 = new TableCell();
tRow.Cells.Add(cell4);
((IParserAccessor) cell4).AddParsedSubObject(chklist[i]);
chklist[i].ID = "cbx_" + i.ToString();
string a = "processChechBox('" + "ctl00_ContentPlaceHolder1_" + chklist[i].ID + "'); return false;";
chklist[i].Attributes.Add("onChange", a);
chklist[i].Attributes.Add("runat", "server");
}
Session["chk"] = chklist;
}
function processChechBox(id) {
//here is the javascript function for checkbox onChange event
debugger;
var containerRef = document.getElementById(id);
var data = document.getElementById(id);
data.value = '1';
data.checked = true;
var a = '<%= Session["chk"]%>';
}
var a = '<%= Session["chk"]%>';
此行返回System.Collections.Generic.List1[System.CheckBox]
而不是列表
processChechBox(id)
,在每个选中的复选框上都会调用此函数。