Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
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 16:46pm
Edited 9-Nov-12 21: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 at 9-Nov-12 23:49pm
   
sorry did u mean autopostback true for 2nd dropdown is it
a2ulthakur at 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 at 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 at 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
0 OriginalGriff 6,656
1 Sergey Alexandrovich Kryukov 6,490
2 CPallini 5,310
3 George Jonsson 3,584
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web03 | 2.8.140921.1 | Last Updated 12 Feb 2013
Copyright © CodeProject, 1999-2014
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