Click here to Skip to main content
13,249,813 members (65,934 online)
Rate this:
 
Please Sign up or sign in to vote.
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 :
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 9-Nov-12 17:46pm
Updated 9-Nov-12 22:37pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try setting autopostback to true in your dropdownlist
  Permalink  
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
Soumen_Banerjee 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
......
}
Anusha SR 10-Nov-12 1:52am
   
Do check ur project with a breakpoint, u may findout where the value of dropdown changes
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

 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();
        }
 

    }
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 12 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100