收集编程技巧 摘录程序源代码 学习优秀代码 眼过千遍 不如手过一遍 让你在线测试源码运行效果
收藏本页到>>
新浪ViVi
365Key网摘
IE收藏夹
|
设为首页
中国搜首页
>>
ASP.NET代码
>>CheckBoxList的AutoPostBack属性
如果允许CheckBoxList控件的AutoPostBack属性,只要有复选框被选定和取消选定,那么保含该CheckBoxList的表单就被提交。
程序清单中,在用户选定一个新的复选框时,就触发SelectedIndexChanged事件。该事件与chklFavoriteFoods_SelectedIndexChanged子程序关联,因此只要选定了新的复选框,页面就自动被提交到服务器,chklFavoriteFoods_SelectedIndexChanged子程序就被执行。
<Script Runat="Server"> Sub chklFavoriteFoods_SelectedIndexChanged( s As Object, e As EventArgs ) Dim itmFood As ListItem Dim strList As String For each itmFood in chklFavoriteFoods.Items If itmFood.Selected Then strList &= "<li>" & itmFood.Text End If Next lblFoodList.Text = strList End Sub </Script> <html> <head><title>CheckBoxListAutoPostBack.aspx</title></head> <body> <form Runat="Server"> <asp:CheckBoxList ID="chklFavoriteFoods" AutoPostBack="True" OnSelectedIndexChanged="chklFavoriteFoods_SelectedIndexChanged" Runat="Server"> <asp:ListItem Text="Pizza" /> <asp:ListItem Text="Hamburgers" Selected="True"/> <asp:ListItem Text="Pasta"/> </asp:CheckBoxList> <hr> You like to eat: <asp:Label ID="lblFoodList" Runat="Server" /> </form> <!--以下为本站的广告代码,请在使用代码时加以删除.本站广告代码开始--> <script type="text/javascript"><!-- google_ad_client = "pub-4055365977023692"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text_image"; google_ad_channel =""; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "0000FF"; google_color_url = "008000"; google_color_text = "000000"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <!--本站广告代码结束--> </body> </html>
运行演示代码
上一页
下一页
Since 2004 www.zhonguosou.com