Monday, January 28, 2008

数据资料的显示,修改等,内容太多,给出一部分了

定义datagrid的页导航和脚注。
private void Dg_DownList_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
this.tbl_DownList.Visible =true;
ListItemType elemtype =e.Item.ItemType;

if(elemtype ==ListItemType.Pager)
{
TableCell pager =(TableCell)e.Item.Controls[0];

for(int i=0;i {
object o=pager.Controls[i];
if(o is LinkButton)
{
LinkButton h =(LinkButton)o;
h.CssClass="blue";
h.Text ="[" +h.Text+ "]";
}
else
{
Label l=(Label)o;
l.CssClass="red";
l.Text = "第" + l.Text + "页";
}
}
}

if(elemtype ==ListItemType.Footer)
{
TableCellCollection tcc =e.Item.Cells;
int ntotalcols =tcc.Count;
for(int i=0;i
{
e.Item.Cells.RemoveAt(1);
}
TableCell c =e.Item.Cells[0];
c.HorizontalAlign =HorizontalAlign.Right;
c.ColumnSpan =ntotalcols;
c.Text ="共有 " + itemcount +"项,当前是 "+ this.Dg_DownList.CurrentPageIndex.ToString()
+"/" + itemcount/this.Dg_DownList.PageSize +"页 ";
}
}
定义数据源,和datagrid的实际项数
private System.Data.OleDb.OleDbDataReader CreateDataSource(int nPageIndex)
{
int npagesize =this.Dg_DownList.PageSize;
int nBaseID =nPageIndex * npagesize;
string DbName =Server.MapPath(@"..\db\Sources.mdb");
string ConnSourcesStr ="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + DbName;
Dbconn_Sources =new System.Data.OleDb.OleDbConnection(ConnSourcesStr);
Dbconn_Sources.Open();
string strCmd ="SELECT TOP " + npagesize + " " +
"*" +
"FROM Download " +
"WHERE ID >" + nBaseID;
Dbcom_Admin =new System.Data.OleDb.OleDbCommand(strCmd,Dbconn_Sources);
Dr_Down =Dbcom_Admin.ExecuteReader(CommandBehavior.CloseConnection);
return Dr_Down;
}

public void SetVICount()
{
string DbName =Server.MapPath(@"..\db\Sources.mdb");
string ConnSourcesStr ="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + DbName;
Dbconn_Sources =new System.Data.OleDb.OleDbConnection(ConnSourcesStr);
Dbconn_Sources.Open();
string strcount ="select count(*) from download";
Dbcom_Admin =new System.Data.OleDb.OleDbCommand(strcount,Dbconn_Sources);
int nItemCount =(int)Dbcom_Admin.ExecuteScalar();
Dbconn_Sources.Close();
this.Dg_DownList.VirtualItemCount =nItemCount;
itemcount =this.Dg_DownList.VirtualItemCount;
return;
}
这里是页面切换的
private void Dg_DownList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.tbl_DownList.Visible =true;
this.tbl_ChangeInfo.Visible =false;
try
{
this.Dg_DownList.CurrentPageIndex =e.NewPageIndex;
this.Dg_DownList.DataSource =CreateDataSource(this.Dg_DownList.CurrentPageIndex);
this.Dg_DownList.DataBind();
Dr_Down.Close();
}
catch(Exception ex)
{
Response.Write(" ex.Message.ToString() ");
}
}


Related Posts



0 Comments:

 

gf

rgdfgfdg

gf

gf

gf