在ComboBox的SelectedIndexChanged事件里操作

解决方案 »

  1.   

    给你写个demo,好好看看 asp.net 是如何让两个控件自动绑定的!<%@ Page Language="C#" AutoEventWireup="true" %><script runat="server">
        protected void Button1_Click(object sender, EventArgs e)
        {
            this.Label1.DataBind();
        }
    </script><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:DropDownList ID="DropDownList1" runat="server">
                <asp:ListItem>张三</asp:ListItem>
                <asp:ListItem>李四</asp:ListItem>
                <asp:ListItem>王五</asp:ListItem>
                <asp:ListItem>赵六</asp:ListItem>
            </asp:DropDownList>
            &nbsp;&nbsp;&nbsp;
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="提交" />
            <br />
            <br />
            你选择的是:<asp:Label ID="Label1" runat="server" Text="<%# DropDownList1.Text %>"></asp:Label>
        
        </div>
        </form>
    </body>
    </html>
      

  2.   

    下面的示例演示如何将 SelectionChanged 事件附加到列表框控件。 
    <TextBox Name="tb" Width="140" Height="30"></TextBox>
    <ListBox Name="lb" Width="100" Height="55" SelectionChanged="PrintText" SelectionMode="Single">
      <ListBoxItem>Item 1</ListBoxItem>
      <ListBoxItem>Item 2</ListBoxItem>
      <ListBoxItem>Item 3</ListBoxItem>
      <ListBoxItem>Item 4</ListBoxItem>
      <ListBoxItem>Item 5</ListBoxItem>
      <ListBoxItem>Item 6</ListBoxItem>
      <ListBoxItem>Item 7</ListBoxItem>
      <ListBoxItem>Item 8</ListBoxItem>
      <ListBoxItem>Item 9</ListBoxItem>
      <ListBoxItem>Item 10</ListBoxItem>
    </ListBox>
    void PrintText(object sender, SelectionChangedEventArgs args)
    {
        ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem);
        tb.Text = "   You selected " + lbi.Content.ToString() + ".";
    }
      

  3.   

    面的示例演示如何处理 SelectionChanged 事件。 Visual Basic  复制代码 
    Private Sub PrintText(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)    Dim lbsender As ListBox
        Dim li As ListBoxItem    lbsender = CType(sender, ListBox)
        li = CType(lbsender.SelectedItem, ListBoxItem)
        tb.Text = "   You selected " & li.Content.ToString & "."
    End Sub
     
    C#  复制代码 
    void PrintText(object sender, SelectionChangedEventArgs args)
    {
        ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem);
        tb.Text = "   You selected " + lbi.Content.ToString() + ".";
    }