0
 <asp:DropDownList ID="DropDownList1" runat="server" Width="128px" Height="32px" 
            onselectedindexchanged="DropDownList1_SelectedIndexChanged" 
            style="position: relative; top: 3px; left: 4px">
            <asp:ListItem>.......SELECT.......</asp:ListItem>
            <asp:ListItem>Membership</asp:ListItem>
            <asp:ListItem>Publication</asp:ListItem>
            <asp:ListItem>Journal</asp:ListItem>
            <asp:ListItem>Additional Activity</asp:ListItem>
            <asp:ListItem>Guide Details</asp:ListItem>
            <asp:ListItem>Project</asp:ListItem>
            <asp:ListItem>Workshop</asp:ListItem>


   //c# code to call the list items
 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex == Convert.ToInt32(0))
        {

        }
    }
4

3 回答 3

0

在 drpdownlist 的 DropDownList1_SelectedIndexChanged 事件中编写代码

if (DropDownList2.SelectedIndex == Convert.ToInt32(0))
    {  
        your display code;
    }
else if(DropDownList2.SelectedIndex == Convert.ToInt32(1))
    {  
        your display code;
    }

等等... 使用 sqldatareader 显示记录列表以显示记录

string qry="select * from your table name where youcolumforddl='" + DropDownList2.SelectedValue.ToString() + "'";
 SqlCommand cmd = new SqlCommand(qry, yourconnection);
        SqlDataReader dr=cmd.ExecuteReader();
        if(dr.HasRows)
        {
            yourcontrols=dr[0].ToString();
            ....
            ....
            if contorlis int type=Convert.ToInt32(dr[3]);
        }
        dr.Close();
        cmd.Dispose();
于 2013-09-07T05:19:53.503 回答
0

从数据库或集合中获取数据。将下拉列表的数据源属性设置为该源

List<strig> data = // set list from db or from any collection.
DropdownList1.DataSource=data;
DropdownList1.DtataBind();

这会将内容从源加载到下拉列表。源可以是任何集合。

您还可以设置下拉列表的DataTextField 和DataValueFiled 来指定选择下拉项时集合的哪个属性显示为文本以及集合的哪个属性作为值。

DropDownList1.DataTextFiled="Name";
DropDownList1.DataValueField="id";
于 2013-09-07T05:49:20.390 回答
0

尝试这个:

<asp:DropDownList ID="DropDownList1" runat="server" Width="128px" Height="32px" Style="position: relative;
            top: 3px; left: 4px" >
            <asp:ListItem>.......SELECT.......</asp:ListItem>
            <asp:ListItem>Membership</asp:ListItem>
            <asp:ListItem>Publication</asp:ListItem>
            <asp:ListItem>Journal</asp:ListItem>
            <asp:ListItem>Additional Activity</asp:ListItem>
            <asp:ListItem>Guide Details</asp:ListItem>
            <asp:ListItem>Project</asp:ListItem>
            <asp:ListItem>Workshop</asp:ListItem>
        </asp:DropDownList>

C#:在按钮单击事件中,您可以添加相同的

 protected void btnView_Click(object sender, EventArgs e)
{
        if (DropDownList1.SelectedItem.Text == "Membership")// here you can add selectedindex as well
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionStringName"].ToString());
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter("select columname from tablename where itemanme=Membership", con);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            con.Close();
            gridview1.DataSource=dt; // assign dt to the datasource of grid
            gridview1.DataBind();

        }
    }
于 2013-09-07T05:50:27.350 回答