大家好, 我有数据库表leave_rec(name,date1,leave,ltype),下拉列表和gridview。 我想这样做当我在下拉列表中选择月份(例如2月)时,gridview应该仅显示fabruary月份的所有表值(egrohan leuva,2/28/2013,full,casual),表示月份= 2(2月)的记录。如何克服这个问题?我试过,但我现在只能在gridview中显示所有的值。任何帮助都会受到极大的关注。
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.
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();上面的代码显示date1,leave,ltype for dropdownlist1.selectedvalue.but now我希望第二次下拉,其中几个月将在那里。所以当我在第二个选择fabruary时,网格应显示dropdownlist1.selectedvalue 的值仅适用于fabruary。
推荐答案过滤数据表然后重新绑定gridview 例如: DataView dv = ds.Tables [0] .DefaultView; dv.RowFilter =date1 = Feb filter data table with then rebind the gridview e.g: DataView dv=ds.Tables[0].DefaultView; dv.RowFilter = "date1=Feb" GridView1.DataSource = dv; GridView1.DataBind();
更多推荐
根据下拉列表值从数据库中选择值
发布评论