datalist 控件绑定数据不显示,数据库里面不为空

yuyij 2014-01-07 01:27:25
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class desktopmodules_putong : System.Web.UI.Page
{
DataOperate sqlBind = new DataOperate();
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
protected void Page_Load(object sender, EventArgs e)
{
dlbind();
}
public void dlbind() {
string idStr = Page.Request.QueryString["titleid"];
int curpage = Convert.ToInt32(this.labPage.Text);

PagedDataSource ps = new PagedDataSource();
con.Open();
string str = "select * from title_view where titleid='" + idStr + "'";
SqlDataAdapter m = new SqlDataAdapter(str,con);
DataSet ds = new DataSet();
m.Fill(ds,"title");
con.Close();
ps.DataSource = ds.Tables["title"].DefaultView;
ps.AllowPaging = true;
ps.PageSize = 2;
ps.CurrentPageIndex = curpage - 1;
up.Enabled = one.Enabled = back.Enabled = next.Enabled = true;
if(curpage==1){
one.Enabled = false;
up.Enabled = false;
}
if (curpage == ps.PageCount) {
next.Enabled = false;
back.Enabled = false;
}
this.labbackpage.Text = Convert.ToString(ps.PageCount);
this.dl.DataSource = ps;
this.dl.DataKeyField = "titleid";
this.dl.DataBind();

}
protected void one_Click(object sender, EventArgs e)
{
this.labPage.Text = "1";
this.dlbind();
}
protected void up_Click(object sender, EventArgs e)
{
this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text)-1);
this.dlbind();
}
protected void next_Click(object sender, EventArgs e)
{
this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text)+1);
this.dlbind();
}
protected void back_Click(object sender, EventArgs e)
{
...全文
109 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
枫飞叶 2014-01-07
  • 打赏
  • 举报
回复
直接换集合看看显示不,前台绑定没?
yuyij 2014-01-07
  • 打赏
  • 举报
回复
还是不行,不显示
枫飞叶 2014-01-07
  • 打赏
  • 举报
回复
this.dl.DataSource = ps; 换成 this.dl.DataSource = ds.Tables["title"].DefaultView;试试
yuyij 2014-01-07
  • 打赏
  • 举报
回复
这个是DataOperate类 public class DataOperate { SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conStr"]); public DataOperate() { } public bool DataCom(string sqlstr) { con.Open(); SqlCommand sqlcomm = new SqlCommand(sqlstr, con); try { sqlcomm.ExecuteNonQuery(); return true; } catch { return false; } finally { con.Close(); } } public bool gvBind(GridView gv, string sqlstr) { con.Open(); SqlDataAdapter sqldataadapter = new SqlDataAdapter(sqlstr, con); DataSet mydataset = new DataSet(); sqldataadapter.Fill(mydataset); gv.DataSource = mydataset; try { gv.DataBind(); return true; } catch { return false; } finally { con.Close(); } } public bool dataBind(DataList dl, string sqlstr) { con.Open(); SqlDataAdapter myadapter = new SqlDataAdapter(sqlstr, con); DataSet mydataset = new DataSet(); myadapter.Fill(mydataset); dl.DataSource = mydataset; try { dl.DataBind(); return true; } catch { return false; } finally { con.Close(); } } }
yuyij 2014-01-07
  • 打赏
  • 举报
回复
各位帮忙看看,哪有问题,就是不显示

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧