在C#中从gridview中搜索 [英] search from gridview in C#

查看:78
本文介绍了在C#中从gridview中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在gridview中搜索某些记录时,错误消息显示为

指定的参数超出了有效值的范围



代码为:

 con.Open(); 
string query = 从View中选择名称其中ID如' + txtID.Text + %';
SqlDataAdapter da = new SqlDataAdapter(query,con);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables [ 0 ]。Rows.Count > 0
{
GridViewItm.DataSource = ds;
GridViewItm.DataBind();
GridViewItm.Show();
}
else
{
Response.Write( @ < script language ='javascript'> alert('未找到请求的记录')< / script>);
}



所以请,任何人都建议我一些答案......

解决方案

我不太清楚..



但我知道。



< pre lang =text> con.Open();
string query =从View中选择名称,其中ID类似于'+ txtID.Text +%';
SqlDataAdapter da = new SqlDataAdapter(query,con);
DataSet ds = new DataSet();
da.Fill(ds);
if(ds.Tables [0] .Rows.Count> 0)
{
GridViewItm.DataSource = ds.Tables [0]; //编辑!
}
其他
{
Response.Write(@< script language ='javascript'> alert('未找到请求的记录')< / script> );
}


1。检查DataSet是否包含Table并处理它如果没有。

2.如果DataSet有Table,那么检查Table是否有行。

3.最后将DataSet绑定到GridView数据源,如ds.Tables [0];


when I am searching for some records in gridview, the error message is showing like
"Specified argument was out of the range of valid values"

the code is:

con.Open();
string query = "select Name from View where ID like'" + txtID.Text +"%'";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
    GridViewItm.DataSource = ds;
    GridViewItm.DataBind();
    GridViewItm.Show();
}
else
{
    Response.Write(@"<script language='javascript'>alert('Requested Records Not Found')</script>");
}


So please,, anyone suggest me some answers...

解决方案

i don't know well..

but, i have idea.

con.Open();
 string query = "select Name from View where ID like'" + txtID.Text +"%'";
 SqlDataAdapter da = new SqlDataAdapter(query, con);
 DataSet ds = new DataSet();
 da.Fill(ds);
 if (ds.Tables[0].Rows.Count > 0)
 {
 GridViewItm.DataSource = ds.Tables[0];  // Edit!
 }
 else
 {
 Response.Write(@"<script language='javascript'>alert('Requested Records Not Found')</script>");
 }


1. Check whether the DataSet contains Table and handle it If does not.
2. If the DataSet has Table then check the Table has rows.
3. Finally Bind the DataSet to the GridView Datasource like ds.Tables[0];


这篇关于在C#中从gridview中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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