'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents msg As System.Web.UI.WebControls.Label
'Protected WithEvents ckpopedom As System.Web.UI.WebControls.CheckBoxList
Protected WithEvents checklist As System.Web.UI.WebControls.CheckBoxList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Page.IsPostBack = False Then
Dim myconn As SqlConnection
Dim mycmd As SqlCommand
Dim sqlap As SqlDataReader
myconn = New SqlConnection(ConfigurationSettings.AppSettings("conn"))
mycmd = New SqlCommand("SELECT * from class where parentid=1", myconn)
Try
mycmd.Connection.Open()
sqlap = mycmd.ExecuteReader
If sqlap.HasRows = False Then
msg.Text = "无绑定内容!"
End If
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Int16
Dim s As String
For i = 0 To i = checklist.Items.Count - 1
If checklist.Items(i).Selected = True Then
s &= checklist.Items(i).Text
End If
Next
Response.Write(s)
End Sub
Function dbopration(ByVal i As Char) As String
Dim myconn1 As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("conn"))
Dim mycmd1 As SqlCommand = New SqlCommand("Insert into popedom([userid],[classid]) values(@userid,@classid)", myconn1)
将CheckboxList的DataTextField设为classtext,DataValueField设为id.再为循环判断是否选中
System.Text.StringBuilder strSQL = new StringBuilder();
foreach(ListItem li in CheckBoxList.Items)
{
if (li.selected)
{
strSQL.Append("insert into ............;");
}
}
执行strSQL.ToString();中的SQL语句。