想要采用动态添加CHECKBOXLIST的方法,经过实验,产生错误。如果myCheckboxlist.onselectedindexchanged="changed"去掉就可以生成了,可是没有这个就没有意义了,到底要怎么解决,请大家帮忙一下。
编译器错误信息: BC30390: “System.Web.UI.WebControls.ListControl.Protected Overridable Sub OnSelectedIndexChanged(e As System.EventArgs)”是“Protected”,因此它在此上下文中无法访问。
源错误:
行 35: myCheckboxlist.textalign=textalign.right
行 36: myCheckboxlist.autopostback="true"
行 37: MyCheckboxlist.onselectedindexchanged="changed"
行 38: dim myListItem as listitem
行 39: dim j as integer=0
<%@ Page Language="VB" %>
<script runat="server">
' Insert page code here
'
sub page_load(sender as object,e as eventargs)
getCheckboxlist()
end sub
sub getCheckboxlist()
dim i as integer=0
for i=0 to 5
'生成新的行
dim r as tablerow=new tablerow
dim rid as string="R" & i.tostring()
r.id=rid
'生成表行的第一个CELL
dim c1 as tablecell=new tablecell
dim c1id as string="C1" & i.tostring()
c1.id=c1id
c1.text="Checkboxlist No:" +i.tostring()
r.cells.add(c1)
'生成表行的第二个CELL
dim c2 as tablecell=new tablecell
dim c2id as string="c2" +i.tostring()
c2.id=c2id
r.cells.add(c2)
'生成一个CHECKBOXLIST
dim mycheckboxlist as checkboxlist=new checkboxlist()
dim myCheckBoxListID AS string="A" & I.tostring()
mycheckboxlist.id=myCheckBoxListID
myCheckboxlist.repeatColumns="4"
myCheckboxlist.repeatdirection=repeatdirection.horizontal
myCheckboxlist.repeatlayout=repeatlayout.table
myCheckboxlist.textalign=textalign.right
myCheckboxlist.autopostback="true"
MyCheckboxlist.onselectedindexchanged="changed"
dim myListItem as listitem
dim j as integer=0
'为CHECKBOXLIST填充LISTITEM
for j=0 to 7
mylistitem=new listitem
mylistitem.text="aaa"+j.tostring
mylistitem.value="yyy"+j.tostring
mycheckboxlist.items.add(mylistitem)
next
c2.controls.add(mycheckboxlist)
t1.rows.add(r)
next
end sub
sub changed(sender as object,e as eventargs)
end sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<!-- Insert content here -->
<asp:Table id="t1" runat="server"></asp:Table>
</form>
</body>
</html>