永发信息网

C# GridView数据绑定后不显示

答案:6  悬赏:10  手机版
解决时间 2021-03-30 14:46
C# GridView数据绑定后不显示
最佳答案
首先,你的gridview里面没有东西
怎么 selectindexchange
写到pageload里面去

你也要写成ds.Table["Content"];
或者
sda.Fill(ds);
GridView1.DataSource = ds.Table[0];

sqldataadapter自动打开和关闭连接
不需要open() close()追问不行啊!~追答哪里报错?追问con.Open();
sda.Fill(ds);
this.GridView1.DataSource = ds.Tables[0];
this.GridView1.DataKeyNames = new String[] { "CId" };
this.GridView1.DataBind();
con.Close();
}改成这样 content 对象无效追答我的却是没有问题啊。
我用了pubs 数据库里面的employee  完全没有问题
            SqlDataAdapter sda = new SqlDataAdapter("select *  from employee", con);
            DataSet ds = new DataSet();
            sda.Fill(ds, "Content");
            this.GridView1.DataSource = ds.Tables["content"];
            this.GridView1.DataBind();
是不是 表名 错了啊

全部回答
protected void Page_Load(object sender, EventArgs e)
{
if(!ispostback)
{
/////////
}
}
("Server=PC2011011313JZT.\\SQLEXPRESS;DataBase=LTDB;Integrated Security=sspi;");
你能确定连接上数据库?
("Data Source=PC2011011313JZT.\SQLEXPRESS;DataBase=LTDB;Integrated Security=sspi;");
查询语句中试试
dbo.Content
只能写this.GridView1.DataSource = ds.tables[“Content”]; 而且还是 不行 提示Content 对象无效
--------------
有没有试过将 sda.Fill(ds, "Content");
去掉命名,直接写成: sda.Fill(ds);
然后this.GridView1.DataSource = ds.tables[0];
//如果这样还有错的话,我觉得可以检查一下数据库和数据库连接是否正确。
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Server=PC2011011313JZT.\\SQLEXPRESS;DataBase=LTDB;Integrated Security=sspi;");
SqlDataAdapter sda = new SqlDataAdapter("select * from Content", con);
DataSet ds = new DataSet();
con.Open();
sda.Fill(ds, "Content");
this.GridView1.DataSource = ds;
this.GridView1.DataKeyNames = new String[] { "CId" };
this.GridView1.DataBind();
con.Close();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}追问哪位大虾 能帮我解决下啊 !~ 提示错误 Content 无效追答Content 你的数据库有没有这个表啊?
放到load里面去
SqlConnection con = new SqlConnection("Server=PC2011011313JZT.\\SQLEXPRESS;DataBase=LTDB;Integrated Security=sspi;");
SqlDataAdapter sda = new SqlDataAdapter("select * from Content", con);
DataSet ds = new DataSet();
con.Open();
sda.Fill(ds, "Content");
this.GridView1.DataSource = ds.Tables["Content"];
this.GridView1.DataKeyNames = new String[] { "CId" };
this.GridView1.DataBind();
con.Close();追问按你说的这样了
行 16: DataSet ds = new DataSet();
行 17: con.Open();
行 18: sda.Fill(ds,"Content");
行 19: this.GridView1.DataSource = ds.Tables["Content"];
行 20: this.GridView1.DataKeyNames = new String[] { "CId" };
源文件: c:\Inetpub\wwwroot\mysite\LT1\c1\Default.aspx.cs 行: 18
堆栈跟踪:
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
请问我的迈腾车有大灯随动转向功能吗?高手解
钛酸锂的理论容量是多少
the purring of the freezer had been the se
佛教强调利他和自利,请问是什么关系
男人太矮怎么办
耐克,想去投资一个专卖店,大概需要多少钱
私募股权基金是怎样在国内兴起的
可变现净值怎么算?
人为什么会挑食?
51有人用过吗?还可以吗?
x光机中mas大小的作用
在分手半年的前男友面前尿裤子了好心塞以后要
电机磁路饱和是什么意思?
-5分之2-丨-3 2丨 (-3又5分之3)答案是什么?
北美州五湖分别是那五湖
推荐资讯
thiswouldmakeyougood为什么用would
蓝宝石hd7770 1g d5白金版显卡怎么样
想知道东北的一种冰上玩的冰猴是什么做的。
CCD与CMOS的区别?和各自优点??
我们学校连续好几届的学生都在俊鹏嘉艺学编导
是不是只有一所大学发拟录取信息到你手机上?
用水浸了一夜的米还能吃吗
找个漂亮媳妇好,还是丑媳妇好,
2.5米乘3.3米的客厅怎么装修
在工厂上班顺便偷了30多斤铜线,被当场发现了
奇虎360恶意从银行卡上扣款
一没本钱二没技术三没力气在短时间才样才能赚
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?