不太明白你的意思,最好贴出你的代码。不过刚开始的时候肯定没有,你要先给他值,然后再在Page_Load里取
解决方案 »
- Help,asp.net如何实现每隔5分钟扫描数据库中的一张表
- 在网页中实现视频聊天有什么好的控件?
- Vs2005 怎么读不出access数据,简单问题
- 为什么GridView点击按钮执行了命令之后,样式全都改变了?
- Windows XP SP2,.net2003中无法调用javascript脚本的js文件。高手帮忙!!!在先等!!!
- .NET中传参数问题..???求救
- (在线等)关于checkboxlist的问题,如何从数据库里读出多个值,显示在checkboxlist上选择的项!
- 如何给Html控件赋值?
- 请教高手一个变量的问题,麻烦看一下啊
- 请教用VS环境开发的ASP.NET的发布问题(200分送上!)
- asp.net里面Forms验证问题!!!!!
- 怎样实现imagebutton的Enabled?
private void Page_Load(object sender, System.EventArgs e)
{
ViewState["Para"]="Text";
Resposne.Write( ViewState["Para"].ToString());
}
在用这个控件时先调用CopyDatanamespace Liufeng.ClientQuery.UserControl
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls; /// <summary>
/// DataGridWithPage 的摘要说明。
/// </summary>
public abstract class DataGridWithPage : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.LinkButton btnPrevious;
protected System.Web.UI.WebControls.LinkButton btnNext;
protected System.Web.UI.WebControls.DataList DataList1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected int iRowCount; //总的行数
protected int iRowPerPage=5; //每页的行数
protected int iListPageSize=5; //每列表的页数
protected int iModelType=1; //显示模式,页数或下一页 1:上一页 0:数值
protected int iTotalListPage;
protected System.Web.UI.WebControls.ListBox ListBox1;
protected System.Web.UI.HtmlControls.HtmlGenericControl P1;
protected System.Web.UI.HtmlControls.HtmlGenericControl P2; //总共的列表数
protected int iCurrentListPage; //当前的列表
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
btnNext.Enabled=false; //
btnPrevious.Enabled=false;
DataGrid1.PageSize=iRowPerPage;
}
String selectionId = Request.Params["category"];
if((selectionId != "") && (!object.Equals(null,selectionId)))
{ RefreshDataForList(Convert.ToInt16( Request.Params["category"]));
} } #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// 设计器支持所需的方法 - 不要使用
/// 代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnPrevious.Click += new System.EventHandler(this.btnPrevious_Click);
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnPrevious_Click(object sender, System.EventArgs e)
{
btnNext.Enabled = true;
int iCurrentPage = (int)(ViewState["CurrentPage"]);
iCurrentPage--;
ViewState["CurrentPage"]=iCurrentPage;
if (iCurrentPage >= 0)
{
FillGrid(iCurrentPage);
}
if (iCurrentPage==1)
{
btnPrevious.Enabled=false;
} } private void btnNext_Click(object sender, System.EventArgs e)
{
int iCurrentPage = (int)(ViewState["CurrentPage"]);
iCurrentPage++;
ViewState["CurrentPage"]=iCurrentPage;
btnPrevious.Enabled=true;
FillGrid(iCurrentPage);
}
public void CopyData(DataSet ds)
{
iRowCount=ds.Tables["table"].Rows.Count ; if ((iRowCount/iRowPerPage/iListPageSize)>Math.Abs(iRowCount/iRowPerPage/iListPageSize))
{
iTotalListPage=Math.Abs(iRowCount/iRowPerPage/iListPageSize)+1;
}
else
{
iTotalListPage=Math.Abs(iRowCount/iRowPerPage/iListPageSize);
}
iCurrentListPage=1;
ViewState["CurrentPage"]=1;
btnNext.Enabled=true;
btnPrevious.Enabled=false; System.IO.StringWriter sw;
sw = new System.IO.StringWriter();
ds.WriteXml(sw);
ViewState["CopyData"] = sw.ToString();
FillGrid((int)ViewState["CurrentPage"]);
SetListPage(1);
}
private void FillGrid(int iCurrentPage)
{
System.IO.StringReader sr=new System.IO.StringReader((string)ViewState["CopyData"]);
DataSet ds=new DataSet();
ds.ReadXml(sr);
DataTable dt=ds.Tables["table"];
DataView dv=new DataView(dt); string sPageBegin=System.Convert.ToString((iCurrentPage-1)*DataGrid1.PageSize +1);
string sPageEnd=System.Convert.ToString(iCurrentPage*DataGrid1.PageSize +1);
dv.RowFilter="序号>=" + sPageBegin +" and 序号<" + sPageEnd ;
dv.RowStateFilter=DataViewRowState.CurrentRows;
DataGrid1.DataSource=dv;
DataGrid1.DataBind();
if (DataGrid1.Items.Count < DataGrid1.PageSize)
{
btnNext.Enabled = false;
}
}
private void SetListPage(int iCurrentListPage)
{
ViewState["CurrentListPage"]=iCurrentListPage;
String[] values=new String[iListPageSize+2] ;
ListBox1.Items.Clear();
if(iTotalListPage==iCurrentListPage)
{
for (int i=0;i<iListPageSize;i++)
{
if (i==0)
{
values[i]="<<";
ListBox1.Items.Add("<<");
}
else
{
values[i]=Convert.ToString((iCurrentListPage-1)*iListPageSize+i);
ListBox1.Items.Add(Convert.ToString((iCurrentListPage-1)*iListPageSize+i));
}
}
}
else if (iCurrentListPage==1)
{
for (int i=0;i<=iListPageSize;i++)
{
if (i==iListPageSize)
{
values[i]=">>";
ListBox1.Items.Add(">>");
}
else
{
values[i]=Convert.ToString((iCurrentListPage-1)*iListPageSize+i+1);
ListBox1.Items.Add(Convert.ToString((iCurrentListPage-1)*iListPageSize+i+1));
}
}
}
else
{ for (int i=0;i<=iListPageSize;i++)
{
if (i==0)
{
values[i]="<<";
ListBox1.Items.Add("<<");
}
else if (i==iListPageSize)
{
values[i]=(">>");
ListBox1.Items.Add(">>");
}
else
{
values[i]=Convert.ToString((iCurrentListPage-1)*iListPageSize+i+1);
ListBox1.Items.Add(Convert.ToString((iCurrentListPage-1)*iListPageSize+i+1));
}
} }
DataList1.DataSource = values;
DataList1.DataBind();
}
private void RefreshDataForList(int iCategory)
{
string sSelectValue;
sSelectValue=DataList1.Items[iCategory].ToString();
if (sSelectValue=="<<")
{
iCurrentListPage--;
ViewState["CurrentPage"]=(iCurrentListPage+1)*iListPageSize-1; SetListPage(iCurrentListPage);
}
else if (sSelectValue==">>")
{
iCurrentListPage++;
ViewState["CurrentPage"]=iCurrentListPage*iListPageSize+1;
SetListPage(iCurrentListPage);
}
else
{
ViewState["CurrentPage"]=sSelectValue;
}
FillGrid((int)ViewState["CurrentPage"]);
}
public int RowPerPage
{
set
{
iRowPerPage=value;
}
} public int ListPageNumber
{
set
{
iListPageSize=value;
}
}
}
}
http://localhost/MonthDetail.aspx?category=2
这样两个页面间可以保持ViewState吗,不行的话,用什么可以解决我刚接触ASP,有些基本的概念不懂,谢谢大家了
http://localhost/MonthDetail.aspx?category=1
http://localhost/MonthDetail.aspx?category=2当然可以使用ViewState,它的用法与Session一样
{
if (!Page.IsPostBack) //加上这个判断
{
ViewState["Para"]="Text";
Resposne.Write( ViewState["Para"].ToString());
}
}
{
if (Page.IsPostBack) //加上这个判断
{
ViewState["Para"]="Text";
Resposne.Write( ViewState["Para"].ToString());
}
}