根据下拉列表值从数据库中选择值

编程入门 行业动态 更新时间:2024-10-28 08:30:12
本文介绍了根据下拉列表值从数据库中选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我有数据库表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();

更多推荐

根据下拉列表值从数据库中选择值

本文发布于:2023-10-24 07:30:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523327.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!