根据selectedValue下拉列表过滤gridview [英] filter gridview based on a dropdownlist selectedValue

查看:88
本文介绍了根据selectedValue下拉列表过滤gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.
我正在尝试根据DropDownList中的选定值来做一个运动过滤器GridView.
我在下拉列表中有一个名称列表,当我单击名称时,我希望个人信息出现在datagridview中.
我正在尝试这样做:

 受保护的 无效 DropDownList1_SelectedIndexChanged(对象发​​件人,EventArgs e)
       {
           OleDbConnection con =  OleDbConnection(" );
           OleDbDataAdapter dataAdapter =  OleDbDataAdapter( String  .Format(" 从老师那里选择*,其中idteacher = {0}",idteacher),骗子);

           DataTable table =  DataTable();
           dataAdapter.Fill(table);
           GridView1.DataSource =表;
          }



但它不起作用,并且无法识别"Datatable"对象购买C#.
任何人都可以帮助我了解我做错了什么吗?
谢谢!

解决方案


请确保使用System.Data命名空间,然后记住,您应该在asp.net中的数据源绑定之后调用DataBind()方法,所以我想您会忘记它:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
       {
           OleDbConnection con = new OleDbConnection("Data Source=orcl;Persist Security Info=True;User ID=eq;Password=*******;Unicode=True");
           OleDbDataAdapter dataAdapter = new OleDbDataAdapter(String.Format("select * from teacher where idteacher={0} ", idteacher), con);

           DataTable table = new DataTable();
           dataAdapter.Fill(table);
           GridView1.DataSource = table;
           GridView1.DataBind();
          }


最后,我更希望您回顾以下链接:
DataAdapter.Fill()方法的五种不同的重载 [ ^ ]

最好的问候. {
字符串comand =从老师那里选择*";
OracleConnection con =新的System.Data.OracleClient.OracleConnection();
con.ConnectionString = @数据源= orcl;持久安全信息=真实;用户ID = eq;密码= ***; Unicode =真实";
OracleDataAdapter dataAdapter =新的OracleDataAdapter(String.Format(从老师那里选择*,其中idteacher = {0}",命令和反义词),con);

DataTable表=新的DataTable();
dataAdapter.Fill(table);
GridView1.DataSource =表;
GridView1.DataBind();
}

现在我有了datatable对象!
但是我在这一行中遇到了这个错误:dataAdapter.Fill(table);

错误:ORA-00936:缺少表达式´

您知道为什么会出现此错误吗?


Hello.
Im trying to do a exercise filter GridView based on selected value in DropDownList.
I have a list of names in dropdownlist and when i click in the name i want that information of persons appears in datagridview.
Im trying do this like this:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
       {
           OleDbConnection con = new OleDbConnection("Data Source=orcl;Persist Security Info=True;User ID=eq;Password=*******;Unicode=True");
           OleDbDataAdapter dataAdapter = new OleDbDataAdapter(String.Format("select * from teacher where idteacher={0} ", idteacher), con);

           DataTable table = new DataTable();
           dataAdapter.Fill(table);
           GridView1.DataSource = table;
          }



but its not working, and "Datatable" object is not recognized buy c#.
Anyone can help me seeing what im doing wrong?
Thanks!

解决方案

Hi
Please be sure about using System.Data namespace and the after that keep in your mind you should call DataBind() method after data source binding in asp.net so I think you forget it:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
       {
           OleDbConnection con = new OleDbConnection("Data Source=orcl;Persist Security Info=True;User ID=eq;Password=*******;Unicode=True");
           OleDbDataAdapter dataAdapter = new OleDbDataAdapter(String.Format("select * from teacher where idteacher={0} ", idteacher), con);

           DataTable table = new DataTable();
           dataAdapter.Fill(table);
           GridView1.DataSource = table;
           GridView1.DataBind();
          }


At the finally I prefer to you review follow of link:
Five different overloads of the DataAdapter.Fill() method[^]

Best Regards.


protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string comand = "select * from teacher";
OracleConnection con = new System.Data.OracleClient.OracleConnection();
con.ConnectionString = @"Data Source=orcl;Persist Security Info=True;User ID=eq;Password=***;Unicode=True";
OracleDataAdapter dataAdapter = new OracleDataAdapter(String.Format("select * from teacher where idteacher={0} ", comand), con);

DataTable table = new DataTable();
dataAdapter.Fill(table);
GridView1.DataSource = table;
GridView1.DataBind();
}

Now i have datatable object!
But i got this error in this line : dataAdapter.Fill(table);

Error : ORA-00936: missing expression´

Do you know why can be this error?


这篇关于根据selectedValue下拉列表过滤gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆