html:
------------------------------------------
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 304px; POSITION: absolute; TOP: 128px" runat="server" AutoGenerateColumns="False" AllowPaging="True" PageSize="5" Width="480px" Height="320px">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<uc1:SnackShow id="SnackShow1" runat="server" SnackID=<%# DataBinder.Eval(Container.DataItem, "id") %>></uc1:SnackShow>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
----------------------------------------------------------------------------------
代码
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
dgDataBind();
} }
private void dgDataBind()
{
Business.MovieNews mn = new MovieNews();声明业务层对象
this.DataGrid1.DataSource = mn.GetNews("");//获取dataset
this.DataGrid1.DataBind();
}
private void DataGrid1_PageIndexChanged(object source,System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex =e.NewPageIndex;
dgDataBind();
}
-----------------------------------------
症状:
一开始运行,dg里的控件显示正常,但是一翻页,dg里的控件就没有绑定(因为dg里的控件有图片
显示叉号,还有其他字段没有赋值)。小弟百思不得其解
烦请各位高手指点
------------------------------------------
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 304px; POSITION: absolute; TOP: 128px" runat="server" AutoGenerateColumns="False" AllowPaging="True" PageSize="5" Width="480px" Height="320px">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<uc1:SnackShow id="SnackShow1" runat="server" SnackID=<%# DataBinder.Eval(Container.DataItem, "id") %>></uc1:SnackShow>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
----------------------------------------------------------------------------------
代码
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
dgDataBind();
} }
private void dgDataBind()
{
Business.MovieNews mn = new MovieNews();声明业务层对象
this.DataGrid1.DataSource = mn.GetNews("");//获取dataset
this.DataGrid1.DataBind();
}
private void DataGrid1_PageIndexChanged(object source,System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex =e.NewPageIndex;
dgDataBind();
}
-----------------------------------------
症状:
一开始运行,dg里的控件显示正常,但是一翻页,dg里的控件就没有绑定(因为dg里的控件有图片
显示叉号,还有其他字段没有赋值)。小弟百思不得其解
烦请各位高手指点
解决方案 »
- 如何解觉绑定时使用三元运算符?
- 用asp.net实现聊天室呀 急呀 帮帮忙吧
- 隐私报告 、第三方cookies问题 !遇过的朋友请进
- iis配置问题
- 菜鸟问题:ADO.NET中进行SQL查询直接用Command和用DataAdapter的4个属性查询数据库有何区别?
- 问题还没有解决,希望大家能继续给我提供帮助!Label控件的使用问题
- 如何获取任何错误信息并带到指定页面?
- 从.net framework 1.0+MS SQL SERVER 7.0转到.net framework 2.0+MS SQL SERVER 7.0
- asp.net下载文件问题
- 用户控件中控件属性的实现?
- datagrid太宽了,我想像iframe那样在页面是只显示datagrid的一部分,但下面有滚动条
- 如何用asp.net实现新闻小偷
public SnackID
{
get
{
.....
}
set
{
this.TextBox1.Text=".....";
this.Image1 .......
}
}
我就是想传一个ID进去其他什么都不用做
翻页的时候对DataGrid1重新绑定了。。
<uc1:SnackShow id="SnackShow1" runat="server" SnackID=<%# DataBinder.Eval(Container.DataItem, "id") %>></uc1:SnackShow>
上面的SnackID应该变了。也就是说应该出在你的用户控件。。
也许你希望在控件的Page_Load里根据属性SnackID做文章,但是这些事件执行的先后顺序是这样的:
主页面Page_Load -> 控件Page_Load -> DataGrid翻页 -> DataGrid绑定
namespace DVD.UserControls
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using DVD.Business;
/// <summary>
/// SnackShow 的摘要说明。
/// </summary>
public class SnackShow : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Image img;
protected System.Web.UI.WebControls.Label id;
protected System.Web.UI.WebControls.Label MovieName;
protected System.Web.UI.WebControls.TextBox Mount;
protected System.Web.UI.WebControls.Button Buy;
protected System.Web.UI.WebControls.Label Price; private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
Business.MovieNews mo = new MovieNews(int.Parse(SnackID));
this.MovieName.Text = mo.MovieName;
this.Price.Text = mo.Price;
//this.id.Text = SnackID;
this.img.ImageUrl = "../Web/showsmallimage.aspx?id="+ SnackID +"";
Buy.Attributes["onClick"]="window.open('../../web/shopping/ShopCar.aspx?strID=" + ViewState["id"].ToString() + "&Mount=" + this.Mount.Text +" &visable=1','','width=800,height=800,top=1,left=1,scrollbars=yes');return false;";
} } #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Buy.Click += new System.EventHandler(this.Buy_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnBuy_Click(object sender, System.EventArgs e)
{
// Response.Write("<script>window.open('../../../web/shopping/ShopCar.aspx?strID=" + id.Text + "&monut=" + this.Mount.Text +"');</script>"); } private void Buy_Click(object sender, System.EventArgs e)
{
Response.Write("<script>window.open('../../../web/shopping/ShopCar.aspx?strID=" + ViewState["id"].ToString() + "&monut=" + this.Mount.Text +"');</script>");
}
public String SnackID
{
get
{
return (string)ViewState["id"]; //return id.Text ;
}
set
{
//id.Text = value;
ViewState["id"]= value; }
}
public String SnackPrice
{
get
{
return Price.Text ;
}
set
{
Price.Text = value;
}
}
}
}
---------------------------------------
{
this.DataGrid1.CurrentPageIndex =e.NewPageIndex;
dgDataBind();
}
少句柄了啊 所以没执行
Private Sub dgOrder_PageIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgOrder.PageIndexChanged 你少了这个
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
===========================================
namespace DVD.UserControls
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using DVD.Business;
/// <summary>
///SnackShow 的摘要说明。
/// </summary>
public class SnackShow : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label id;
protected System.Web.UI.WebControls.TextBox Mount;
protected System.Web.UI.WebControls.Button Buy;
protected System.Web.UI.WebControls.Label dmerchant;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label PremieveDate;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.Label MovieLong;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.Label MovieLevel;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Label MovieType;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Player;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Director;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label MoiveName;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Image img;
protected System.Web.UI.WebControls.Label Label12;
protected System.Web.UI.WebControls.Label Price; private void Page_Load(object sender, System.EventArgs e)
{ } #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
} /// <summary>
///设计器支持所需的方法 - 不要使用代码编辑器
///修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Buy.Click += new System.EventHandler(this.Buy_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnBuy_Click(object sender, System.EventArgs e)
{
//Response.Write("<script>window.open('../../../web/shopping/ShopCar.aspx?strID=" + id.Text + "&monut=" + this.Mount.Text +"');</script>"); } private void Buy_Click(object sender, System.EventArgs e)
{
Response.Write("<script>window.open('ShopCar.aspx?strID=" + ViewState["id"].ToString() + "&monut=" + this.Mount.Text +"');</script>");
} public String SnackID
{
get
{
return (string)ViewState["id"]; //return id.Text ;
}
set
{
//id.Text = value;
ViewState["id"]= value;
// if(!this.IsPostBack)
// {
Business.MovieNews mo = new MovieNews(int.Parse(SnackID));
this.MoiveName.Text = mo.MovieName;
this.Price.Text = mo.Price;
Director.Text = mo.Director;
Player.Text = mo.MostylPlayer;
MovieType.Text = mo.MovieType;
MovieLevel.Text = mo.MovieLevel;
MovieLong.Text = mo.MovieLong;
PremieveDate.Text = mo.PremieveDate.ToShortDateString().ToString();
//this.id.Text = SnackID; this.img.ImageUrl = "../Web/showsmallimage.aspx?id="+ SnackID +""; Buy.Attributes["onClick"]="window.open('ShopCar.aspx?strID=" + ViewState["id"].ToString() + "&Mount=" + this.Mount.Text +" &visable=1','','width=800,height=800,top=1,left=1,scrollbars=yes');return false;";
// }
}
}
public String SnackPrice
{
get
{
return Price.Text ;
}
set
{
Price.Text = value;
}
}
}
}
set
{
//id.Text = value;
ViewState["id"]= value;
//if(!this.IsPostBack)
//{
Business.MovieNews mo = new MovieNews(int.Parse(SnackID));
this.MoiveName.Text = mo.MovieName;
this.Price.Text = mo.Price;
Director.Text = mo.Director;
Player.Text = mo.MostylPlayer;
MovieType.Text = mo.MovieType;
MovieLevel.Text = mo.MovieLevel;
MovieLong.Text = mo.MovieLong;
PremieveDate.Text = mo.PremieveDate.ToShortDateString().ToString();
//this.id.Text = SnackID;this.img.ImageUrl = "../Web/showsmallimage.aspx?id="+ SnackID +"";Buy.Attributes["onClick"]="window.open('ShopCar.aspx?strID=" + ViewState["id"].ToString() + "&Mount=" + this.Mount.Text +" &visable=1','','width=800,height=800,top=1,left=1,scrollbars=yes');return false;";
//}