但是在和其他控件在一起的时候回显示不出来,
求高手大大解答。
15 个解决方案
#1
怎么会呢
确认数据源绑定在GridView上?
确认数据源绑定在GridView上?
#2
1、代码贴出来
2、你是不是有js控制了Table的显示隐藏
2、你是不是有js控制了Table的显示隐藏
#3
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
public partial class Default7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindGridView();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bindGridView();
}
protected void bindGridView()
{
SqlConnection conn = new SqlConnection("server=(local);Initial Catalog=qikan;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );
DataSet ds = new DataSet();
sda.Fill(ds,"文章");
DataTable dt = ds.Tables["文章"];
this.GridView1.DataSourceID = null;
this.GridView1.DataSource = ds.Tables["文章"].DefaultView;
this.GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstr = "delete from 文章 where 题目='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlConnection conn = new SqlConnection("server=(local);Initial Catalog=qikan;Integrated Security=True");
SqlCommand sqlcom = new SqlCommand(sqlstr, conn);
conn.Open();
Class1.road = (@"\webmag/UpFiles/\" + GridView1.Rows[0].Cells[7].Text);
File.Delete(Server.MapPath(Class1.road));
sqlcom.ExecuteNonQuery();
conn.Close();
bindGridView();
}
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
public partial class Default7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindGridView();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bindGridView();
}
protected void bindGridView()
{
SqlConnection conn = new SqlConnection("server=(local);Initial Catalog=qikan;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );
DataSet ds = new DataSet();
sda.Fill(ds,"文章");
DataTable dt = ds.Tables["文章"];
this.GridView1.DataSourceID = null;
this.GridView1.DataSource = ds.Tables["文章"].DefaultView;
this.GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstr = "delete from 文章 where 题目='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlConnection conn = new SqlConnection("server=(local);Initial Catalog=qikan;Integrated Security=True");
SqlCommand sqlcom = new SqlCommand(sqlstr, conn);
conn.Open();
Class1.road = (@"\webmag/UpFiles/\" + GridView1.Rows[0].Cells[7].Text);
File.Delete(Server.MapPath(Class1.road));
sqlcom.ExecuteNonQuery();
conn.Close();
bindGridView();
}
#4
你加this.GridView1.DataSourceID = null;这句话干嘛,去掉!
#5
还有SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );这里的SQL语句拿到查询分析器中分析有数据没有??
#6
不加的话由于引用两个数据库会报错,报错代码如下:
System.InvalidOperationException: “GridView1”上同时定义了 DataSource 和 DataSourceID。请移除一个定义。
行 43: //this.GridView1.DataSourceID = null;
行 44: this.GridView1.DataSource = ds.Tables["文章"].DefaultView;
行 45: this.GridView1.DataBind();行 46:
行 47:
System.InvalidOperationException: “GridView1”上同时定义了 DataSource 和 DataSourceID。请移除一个定义。
行 43: //this.GridView1.DataSourceID = null;
行 44: this.GridView1.DataSource = ds.Tables["文章"].DefaultView;
行 45: this.GridView1.DataBind();行 46:
行 47:
#7
后面指定了DataSource的话,前面就别指定DataSourceID了
#8
有数据的,我大概知道错在哪里了,单独的空间为了测试时用的SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );
而实际我在网页中调用的是公共类里面的变量Class1.name(定义代码是static public string name;),代码为SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='+ Class.name +' ",conn );(如果作者="'+ Class.name +'",conn 的话会报错 CS1012: 字符文本中的字符太多)(Class1.name是有值的,label.text里输出的是123)
而实际我在网页中调用的是公共类里面的变量Class1.name(定义代码是static public string name;),代码为SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='+ Class.name +' ",conn );(如果作者="'+ Class.name +'",conn 的话会报错 CS1012: 字符文本中的字符太多)(Class1.name是有值的,label.text里输出的是123)
#9
在*.aspx文件中,把控件的
DataSourceID 属性去掉。
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );
单步调试,看是否有值.
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );
单步调试,看是否有值.
#10
去掉的话显示SqlDataSource1没有定义
有值,能产生gridview表的,但是用一个值为123的变量就不能显示了
有值,能产生gridview表的,但是用一个值为123的变量就不能显示了
#11
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );
DataSet ds = new DataSet();
sda.Fill(ds,"文章");
this.GridView1.DataSource = ds.Tables[0].DefaultView;
this.GridView1.DataBind();
#12
一个不怎么样的问题 高的这样~~呵呵~
#13
那你SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='+ Class.name +' ",conn );这句话中的
Class.name的值是什么???你输出来看了没有?
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='+ Class.name +' ",conn );
中的SQL语句有问题,这样改写:
SqlDataAdapter sda = new SqlDataAdapter( "select * from 文章 where 作者='"+ Class.name +"'",conn );
Class.name的值是什么???你输出来看了没有?
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='+ Class.name +' ",conn );
中的SQL语句有问题,这样改写:
SqlDataAdapter sda = new SqlDataAdapter( "select * from 文章 where 作者='"+ Class.name +"'",conn );
#14
你就是蛋疼,前面绑定了数据源,后面又给了数据源,能不错么
#15
我用了一个label,输出的值是123
#1
怎么会呢
确认数据源绑定在GridView上?
确认数据源绑定在GridView上?
#2
1、代码贴出来
2、你是不是有js控制了Table的显示隐藏
2、你是不是有js控制了Table的显示隐藏
#3
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
public partial class Default7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindGridView();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bindGridView();
}
protected void bindGridView()
{
SqlConnection conn = new SqlConnection("server=(local);Initial Catalog=qikan;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );
DataSet ds = new DataSet();
sda.Fill(ds,"文章");
DataTable dt = ds.Tables["文章"];
this.GridView1.DataSourceID = null;
this.GridView1.DataSource = ds.Tables["文章"].DefaultView;
this.GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstr = "delete from 文章 where 题目='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlConnection conn = new SqlConnection("server=(local);Initial Catalog=qikan;Integrated Security=True");
SqlCommand sqlcom = new SqlCommand(sqlstr, conn);
conn.Open();
Class1.road = (@"\webmag/UpFiles/\" + GridView1.Rows[0].Cells[7].Text);
File.Delete(Server.MapPath(Class1.road));
sqlcom.ExecuteNonQuery();
conn.Close();
bindGridView();
}
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
public partial class Default7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindGridView();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bindGridView();
}
protected void bindGridView()
{
SqlConnection conn = new SqlConnection("server=(local);Initial Catalog=qikan;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );
DataSet ds = new DataSet();
sda.Fill(ds,"文章");
DataTable dt = ds.Tables["文章"];
this.GridView1.DataSourceID = null;
this.GridView1.DataSource = ds.Tables["文章"].DefaultView;
this.GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string sqlstr = "delete from 文章 where 题目='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
SqlConnection conn = new SqlConnection("server=(local);Initial Catalog=qikan;Integrated Security=True");
SqlCommand sqlcom = new SqlCommand(sqlstr, conn);
conn.Open();
Class1.road = (@"\webmag/UpFiles/\" + GridView1.Rows[0].Cells[7].Text);
File.Delete(Server.MapPath(Class1.road));
sqlcom.ExecuteNonQuery();
conn.Close();
bindGridView();
}
#4
你加this.GridView1.DataSourceID = null;这句话干嘛,去掉!
#5
还有SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );这里的SQL语句拿到查询分析器中分析有数据没有??
#6
不加的话由于引用两个数据库会报错,报错代码如下:
System.InvalidOperationException: “GridView1”上同时定义了 DataSource 和 DataSourceID。请移除一个定义。
行 43: //this.GridView1.DataSourceID = null;
行 44: this.GridView1.DataSource = ds.Tables["文章"].DefaultView;
行 45: this.GridView1.DataBind();行 46:
行 47:
System.InvalidOperationException: “GridView1”上同时定义了 DataSource 和 DataSourceID。请移除一个定义。
行 43: //this.GridView1.DataSourceID = null;
行 44: this.GridView1.DataSource = ds.Tables["文章"].DefaultView;
行 45: this.GridView1.DataBind();行 46:
行 47:
#7
后面指定了DataSource的话,前面就别指定DataSourceID了
#8
有数据的,我大概知道错在哪里了,单独的空间为了测试时用的SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );
而实际我在网页中调用的是公共类里面的变量Class1.name(定义代码是static public string name;),代码为SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='+ Class.name +' ",conn );(如果作者="'+ Class.name +'",conn 的话会报错 CS1012: 字符文本中的字符太多)(Class1.name是有值的,label.text里输出的是123)
而实际我在网页中调用的是公共类里面的变量Class1.name(定义代码是static public string name;),代码为SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='+ Class.name +' ",conn );(如果作者="'+ Class.name +'",conn 的话会报错 CS1012: 字符文本中的字符太多)(Class1.name是有值的,label.text里输出的是123)
#9
在*.aspx文件中,把控件的
DataSourceID 属性去掉。
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );
单步调试,看是否有值.
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );
单步调试,看是否有值.
#10
去掉的话显示SqlDataSource1没有定义
有值,能产生gridview表的,但是用一个值为123的变量就不能显示了
有值,能产生gridview表的,但是用一个值为123的变量就不能显示了
#11
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='123' ",conn );
DataSet ds = new DataSet();
sda.Fill(ds,"文章");
this.GridView1.DataSource = ds.Tables[0].DefaultView;
this.GridView1.DataBind();
#12
一个不怎么样的问题 高的这样~~呵呵~
#13
那你SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='+ Class.name +' ",conn );这句话中的
Class.name的值是什么???你输出来看了没有?
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='+ Class.name +' ",conn );
中的SQL语句有问题,这样改写:
SqlDataAdapter sda = new SqlDataAdapter( "select * from 文章 where 作者='"+ Class.name +"'",conn );
Class.name的值是什么???你输出来看了没有?
SqlDataAdapter sda = new SqlDataAdapter("select * from 文章 where 作者='+ Class.name +' ",conn );
中的SQL语句有问题,这样改写:
SqlDataAdapter sda = new SqlDataAdapter( "select * from 文章 where 作者='"+ Class.name +"'",conn );
#14
你就是蛋疼,前面绑定了数据源,后面又给了数据源,能不错么
#15
我用了一个label,输出的值是123