Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The problem is my 'pcode' dropdownlist just works fine but in my 'fyyear' dropdownlist its just showing me values for the first entry only in the gridview like if a project is of two years then its showing me value for first date range lets say for ex 2010-2011 and when i am selecting 2011-2012 nothing is happening and it is automatically showing me the values for first entry only that is 2010-2011??

this is the query i am using on my submit button :
C#
protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {

       
        SqlDataAdapter da = new SqlDataAdapter("select pcode,fyyear,date,salary,ta,contigency,nrc,institcharges,others from monthly where pcode=('" + DropDownList1.SelectedItem.Text + "' ) AND fyyear=('" + DropDownList2.SelectedItem.Text + "')",con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }

        catch (Exception ex)
        {
            ex.Message.ToString();
        }
    }

both fyyear and pcode are varchar

example pcode ICAR/40/34,Dst-23/101
fyyear 2010-2011, 2011-2012 and so on
Posted
Updated 9-Nov-12 21:37pm
v2

Try setting autopostback to true in your dropdownlist
 
Share this answer
 
v2
Comments
a2ulthakur 9-Nov-12 23:49pm    
sorry did u mean autopostback true for 2nd dropdown is it
a2ulthakur 10-Nov-12 0:07am    
and i did that but its of no use..its like it when i select 2nd or 3rd value from dropdownlist 2 it automatically changes my selection to 1st.. one
SoumenBanerjee 10-Nov-12 0:40am    
did you populate dropdownlists on page_load from code behined?
If so this can be happen if these code are out side Ispostback checking
if(!Ispostback)
{
......
populate dropdownlist
......
}
Divya RS 10-Nov-12 1:52am    
Do check ur project with a breakpoint, u may findout where the value of dropdown changes
public void Button2_Click(object sender, EventArgs e)
   {
       try
       {


           SqlDataAdapter da = new SqlDataAdapter("select pcode,fyyear,date,salary,ta,contigency,nrc,institcharges,others from monthly where pcode=('" + DropDownList1.SelectedItem.ToString() + "' ) AND fyyear=('" + DropDownList2.SelectedItem.ToString() + "')", con);
           DataTable dt = new DataTable();
           da.Fill(dt);
           GridView1.DataSource = dt;
           GridView1.DataBind();

           DropDownList1.SelectedIndex = 0;
           DropDownList2.SelectedIndex = 0;
       }

       catch (Exception ex)
       {
           ex.Message.ToString();
       }


   }
 
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