(在DataList中加了一个自定义控件,然后在模板中绑定),点击下一页,DataList内的自定义控件内容不显示(
1、这是我自定义控件的代码:privatestringpid;publicstringPid{get{returnpid;}set{pid=value;}}protect...
1、这是我自定义控件的代码: private string pid;
public string Pid
{
get { return pid; }
set { pid = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
OleDbCommand cmd = new OleDbCommand("select * from [product] where id='" + pid + "'", ConDB.GetCon());
OleDbDataReader oda = cmd.ExecuteReader();
oda.Read();
linkBtnName.Text = oda[2].ToString();
lb_PriceSC.Text = oda[3].ToString();
lb_PriceOnLine.Text = oda[4].ToString();
ImageButton1.ImageUrl = "./Image/"+oda[6].ToString();
}
}
2、DataList分页的代码 public static PagedDataSource pds = null;
private void Bind()
{
OleDbDataAdapter da = new OleDbDataAdapter("select * from product", ConDB.GetCon());
DataTable dt = new DataTable();
da.Fill(dt);
pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = 6;
pds.CurrentPageIndex = PageCount;
DataList1.DataSource = pds;
DataList1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
this.Bind();
LinkBtnUp.Visible = false;
lb_nowPage.Text = "1";
lb_ProductCount.Text = pds.DataSourceCount.ToString();
lb_sumPage.Text =pds.PageCount.ToString();
}
}
3、模板绑定的代码 <ItemTemplate>
<uc1:products ID="Products1" runat="server" Pid=<%# DataBinder.Eval(Container.DataItem,"id") %> />
</ItemTemplate>
当我点击下一页的时候确实分页了,可是数据绑定不上。。。。
这个问题困扰我快一周了,希望大家帮我解决下 在下感激不尽 展开
public string Pid
{
get { return pid; }
set { pid = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
OleDbCommand cmd = new OleDbCommand("select * from [product] where id='" + pid + "'", ConDB.GetCon());
OleDbDataReader oda = cmd.ExecuteReader();
oda.Read();
linkBtnName.Text = oda[2].ToString();
lb_PriceSC.Text = oda[3].ToString();
lb_PriceOnLine.Text = oda[4].ToString();
ImageButton1.ImageUrl = "./Image/"+oda[6].ToString();
}
}
2、DataList分页的代码 public static PagedDataSource pds = null;
private void Bind()
{
OleDbDataAdapter da = new OleDbDataAdapter("select * from product", ConDB.GetCon());
DataTable dt = new DataTable();
da.Fill(dt);
pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = 6;
pds.CurrentPageIndex = PageCount;
DataList1.DataSource = pds;
DataList1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
this.Bind();
LinkBtnUp.Visible = false;
lb_nowPage.Text = "1";
lb_ProductCount.Text = pds.DataSourceCount.ToString();
lb_sumPage.Text =pds.PageCount.ToString();
}
}
3、模板绑定的代码 <ItemTemplate>
<uc1:products ID="Products1" runat="server" Pid=<%# DataBinder.Eval(Container.DataItem,"id") %> />
</ItemTemplate>
当我点击下一页的时候确实分页了,可是数据绑定不上。。。。
这个问题困扰我快一周了,希望大家帮我解决下 在下感激不尽 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询