当DATAGRID通过数据库得到一个空的结果时候,我想给页写一句话: 没有查到相关结果. 该怎么写?

解决方案 »

  1.   

    我用的是ACCESS 数据库,当DATAGRID通过数据库得到一个空的结果时候,我想给页写一句话: 没有查到相关结果. 该怎么写?
    数据库写法如下:
    string dbname;
    dbname=Server.MapPath("lpan.mdb");
    myConnection = new OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + dbname );
    myConnection.Open();
    myCommand = new OleDbCommand( "select lpmc FROM lpan where lpmc like '%"+lpmc1+"%'", myConnection );


    DataGrid1.DataSource=myCommand.ExecuteReader();
    DataGrid1.DataBind(); myConnection.Close();
      

  2.   

    this.DataGrid1.Columns[1].HeaderText="ssssssss";
    or
    在DataGrid1下面放一个Label
    load 中
    this.Label.Visible=false;if(this.DataSet.Table[0].Rows.Count=0)
    {
      this.Label.Visible=true;
      this.Label.Text="............";
    }
    else
    {}
      

  3.   

    我的DATAGRID没有绑定,可以使用DataSet吗?
      

  4.   

    楼上正解 不过犯了个小错误
    if(this.DataSet.Table[0].Rows.Count=0)
    "="改为"=="呵呵
      

  5.   

    出错
    c:\inetpub\wwwroot\loupan\chaxun.aspx.cs(96): “loupan.chaxun”并不包含对“DataSet”的定义
    该如何定义DataSet???没用过DataSet.
      

  6.   

    “/loupan”应用程序中的服务器错误。
    --------------------------------------------------------------------------------无法找到表 0。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IndexOutOfRangeException: 无法找到表 0。源错误: 
    行 95: 
    行 96: 
    行 97:  if(ds.Tables[0].Rows.Count==0)
    行 98:  {
    行 99:  this.DataGrid1.Columns[0].HeaderText="没有查到你想要的结果";
     
      

  7.   

    dbname=Server.MapPath("lpan.mdb");
    myConnection = new OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + dbname );
    myConnection.Open();
    myCommand = new OleDbCommand( "select lpmc FROM lpan where lpmc like '%"+lpmc1+"%'", myConnection );

    if(!myCommand.ExecuteReader())
    {
      this.Label.Visible=true;
      this.Label.Text="............";
    } DataGrid1.DataSource=myCommand.ExecuteReader();
    DataGrid1.DataBind(); myConnection.Close();
      

  8.   

    gridview只要在模板里加<EmptyDataTemplate>
      

  9.   

    加判断 
    if(ds.Tables.Count == 0 || (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count==0))
    {
      //没有结果
    }
      

  10.   

    c:\inetpub\wwwroot\loupan\chaxun.aspx.cs(89): 无法将类型“System.Data.OleDb.OleDbDataReader”转换为“bool”
      

  11.   

    加判断 
    if(ds.Tables.Count == 0 || (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count==0))
    {
      //没有结果
    }
    无论有没有 都是一样的结果