Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
If i choose Dropdown List Value = 0 then i have result all data from database in particular table
Posted
Updated 22-Sep-12 0:31am
v2
Comments
V_R 22-Sep-12 6:55am    
Can you make your quest clear.. In case of select 0 you want data or no..?
[no name] 22-Sep-12 6:57am    
No.... this is not at all a problem. This is not even a question.
Toli Cuturicu 22-Sep-12 18:01pm    
Amen

Hi,

have you tried Google[^].

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


hope it helps.
 
Share this answer
 
v2
Try this !
C#
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);
   }
}
 
Share this answer
 
ASP.NET
<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>


C#
protected void dropDown_SelectedIndexChanged(object sender, EventArgs e)
{
    if (dropDown.SelectedValue != "0")
    {
        //Get your filtered data here..
    }
}
 
Share this answer
 
Use Selected Index Property or Selected Text Property Then you Will get the Required Data
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900