下拉列表问题 [英] dropdown list problem

查看:45
本文介绍了下拉列表问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我选择下拉列表值= 0",那么我得到了特定表中数据库的所有数据.

If i choose Dropdown List Value = 0 then i have result all data from database in particular table

推荐答案



您是否尝试过
Hi,

have you tried Google[^].

protected void dropdown_SelectedIndexChanged(object sender, EventArgs e)
{
   if(dropdown.SelectedValue=="0")
   {
      //Do your job here.
   }
}



希望对您有所帮助.



hope it helps.


尝试一下!
Try this !
protected void dropdown_SelectedIndexChanged(object sender, EventArgs e)
{
   
      string conString = @"Data Source=myServerAddress;
        Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword"; 
      SqlConnection con = new SqlConnection(conString);
        string cmd ="";
       if(dropdown.SelectedValue=="0")
       {
          //fetch all the records 
           cmd =  "selet * from myTable";
        }
        else{
         // fetch records on the bais of  Dropdown Selected value
        cmd = "select * form Table where ColumnName=" + SelectedValue  ;
        }
         //open db connection
        con.Open();
         //execute command with data adapter
        SqlDataAdapter sqlDa = new SqlDataAdapter(cmd, con);
        // create a new table 
        DataTable Dt = new DataTable();
          // fill the table with returned Result
        sqlDa.Fill(Dt);
   }
}


<asp:dropdownlist id="dropDown" runat="server" autopostback="true" onselectedindexchanged="dropDown_SelectedIndexChanged" xmlns:asp="#unknown">
    <asp:listitem text="Select" value="0" selected="True"></asp:listitem>
    <asp:listitem text="Item 1" value="1"></asp:listitem>
    <asp:listitem text="Item 2" value="2"></asp:listitem>
</asp:dropdownlist>





protected void dropDown_SelectedIndexChanged(object sender, EventArgs e)
{
    if (dropDown.SelectedValue != "0")
    {
        //Get your filtered data here..
    }
}


这篇关于下拉列表问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆