Click here to Skip to main content
15,887,341 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone,
I have database table leave_rec(name,date1,leave,ltype),Dropdown list,and a gridview.
I want to do such that,when i select month(e.g. february) in dropdown list,gridview should display all table values for fabruary month only(e.g.rohan leuva,2/28/2013,full,casual),means record which has month=2(february).How to overcome this issue?i tried but i can only display all the values in gridview at this moment.Any help would be greatly appriciated.

C#
SqlConnection conn = new SqlConnection();
conn.ConnectionString=System.Configuration.ConfigurationManager.ConnectionStrings["leave"].ConnectionString;
conn.Open();
SqlCommand cmd = new SqlCommand("select date1,leave,ltype from leave_rec where name='" + DropDownList1.SelectedValue + "'", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();


the above code display the date1,leave,ltype for dropdownlist1.selectedvalue.but now i want to have second dropdown in which months will be there.so when i select fabruary in second one,grid should display value for dropdownlist1.selectedvalue for fabruary only.
Posted
Updated 1-Mar-13 0:57am
v5
Comments
CHill60 1-Mar-13 6:48am    
If you post the code you are using to get all of the values for the grid view we can advise on how to amend it. Use the Improve question link above to put your code snippet into your question
Thanks7872 1-Mar-13 6:54am    
please have a look at the updated question....

1 solution

filter data table with then rebind the gridview
e.g:
DataView dv=ds.Tables[0].DefaultView;

dv.RowFilter = "date1=Feb"

C#
GridView1.DataSource = dv;
GridView1.DataBind();
 
Share this answer
 
v2

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