bindingtosimpleproperties.aspx

来自「这是《ASP.NET编程实作教程》一书中的源文件 如果有此书的朋友不防下载过来参」· ASPX 代码 · 共 45 行

ASPX
45
字号
<html>
<head>
    <script language="C#" runat="server">

        void SubmitBtn_Click(Object sender, EventArgs e) {
        
          // Rather than explictly pull out the variable from the "StateList"
          // and then manipulate a label control, just call "Page.DataBind".
          // This will evaluate any <%# %> expressions within the page
          
          Page.DataBind();
        }

    </script>

</head>
<body>

    <h3><font face="Verdana">DataBinding to a property of another server control</font></h3>

    <form runat=server>

        <asp:DropDownList id="StateList" runat="server">
          <asp:ListItem>CA</asp:ListItem>
          <asp:ListItem>IN</asp:ListItem>
          <asp:ListItem>KS</asp:ListItem>
          <asp:ListItem>MD</asp:ListItem>
          <asp:ListItem>MI</asp:ListItem>
          <asp:ListItem>OR</asp:ListItem>
          <asp:ListItem>TN</asp:ListItem>
          <asp:ListItem>UT</asp:ListItem>
        </asp:DropDownList>
        
        <asp:button Text="Submit" OnClick="SubmitBtn_Click" runat=server/>
        
        <p>
        
        Selected State: <asp:label text='<%# StateList.SelectedItem.Text %>' runat=server/>
        
    </form>

</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?