C# 使用asp.net和c显示列表中的数据# ……选择。。。。。。。 会员 出版 杂志 额外活动 指南详情 项目 车间 //调用列表项的c代码 受保护的void DropDownList1\u SelectedIndexChanged(对象发送方,事件参数e) { if(DropDownList1.SelectedIndex==Convert.ToInt32(0)) { } }

C# 使用asp.net和c显示列表中的数据# ……选择。。。。。。。 会员 出版 杂志 额外活动 指南详情 项目 车间 //调用列表项的c代码 受保护的void DropDownList1\u SelectedIndexChanged(对象发送方,事件参数e) { if(DropDownList1.SelectedIndex==Convert.ToInt32(0)) { } },c#,asp.net,C#,Asp.net,在drpdownlist的DropDownList1\u SelectedIndexChanged事件中编写代码 <asp:DropDownList ID="DropDownList1" runat="server" Width="128px" Height="32px" onselectedindexchanged="DropDownList1_SelectedIndexChanged" style="position: relati

在drpdownlist的DropDownList1\u SelectedIndexChanged事件中编写代码

 <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))
        {

        }
    }
等等。。。 使用sqldatareader显示记录列表 用于显示记录

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

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

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();
试试这个:

DropDownList1.DataTextFiled="Name";
DropDownList1.DataValueField="id";

您可以显示您尝试用于显示数据的代码吗?我不知道如何从代码开始,从何处获取列表项。您是从数据库获取还是对项目进行硬编码?列表项中显示的数据应该从database@user2660112下面的答案是一个开始,我建议你首先在这里进行研究-肯定有很多资源可以帮助你开始。我是asp.net的新手。你能建议我如何使用sqldatareader显示记录列表吗?我编辑了答案,这是一个提示。用它来编写代码谢谢你…@vikas..但我不需要where条件。我想显示整个列表特定Emmber的数据如果要从DropDownList中选择项目,则需要where条件,实际上,您要查找的是“查找代码”。实际上,当我按下“查看”按钮时,它应该显示数据。但在这种情况下,它出现在dropdownlist函数中。如何在按钮中访问..?这些数据应该打印在网格视图中…如何打印..它没有显示..编辑..现在只需查看一下即可代码…我应该在aspx页面中创建gridview吗..?实际上,当我按下view按钮时,它应该显示数据。但在这种情况下,它出现在dropdownlist函数中。如何在按钮中访问..?我理解的是:下拉列表中有一些项目。您已经在DDL中选择了一个项目。你有一个按钮来加载内容。单击按钮时,需要根据ddl中选择的值加载内容。在这种情况下,ddl的SelectedValue属性将给出所选值。字符串x=Dropdownlist1.SelectedValue
DropDownList1.DataTextFiled="Name";
DropDownList1.DataValueField="id";
<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>
 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();

        }
    }