| Protected Sub Page_Load(Src As Object, E As EventArgs) DataBind() End Sub |
| <script language="VB" runat="server"> Sub SubmitBtn_Click(sender As Object, e As EventArgs) Page.DataBind End Sub </script> <B>帮韦小宝选择一个老婆</B> <form runat=server> <asp:DropDownList id="StateList" runat="server"> <asp:ListItem>阿珂</asp:ListItem> <asp:ListItem>曾柔</asp:ListItem> <asp:ListItem>建宁</asp:ListItem> <asp:ListItem>沐公主</asp:ListItem> <asp:ListItem>双儿</asp:ListItem> <asp:ListItem>教主夫人</asp:ListItem> </asp:DropDownList> <asp:button Text="Submit" OnClick="SubmitBtn_Click" runat=server/> <p> 您帮韦小宝选择的老婆是 : <asp:label text='<%# StateList.SelectedItem.Text %>' runat=server/> </form> |
我们看到,那个选择老婆的地方没有使用什么控件,但是他却能正确的显示我们的选择结果,这个是就捆绑的结果,注意<%# StateList.SelectedItem.Text %>这句话,正是它让我们取得了捆绑的数据。更多的地方,我们会经常看到这样的例子,好像程序里面什么都没有,但数据已经绑定在上面了。