Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
update2.cs
Package: Visual.rar [view]
Upload User: yiyuerguo
Upload Date: 2014-09-27
Package Size: 3781k
Code Size: 6k
Category:
CSharp
Development Platform:
Others
- using System;
- using System.Data;
- using System.Data.OleDb;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- namespace www
- {
- public class MyCodeBehind : Page
- {
- public DataGrid MyList;
- public DropDownList DropDownList1;
- public DropDownList DropDownList2;
- public TextBox TextBox1;
- public LinkButton btnFirst;
- public LinkButton btnPrev;
- public LinkButton btnNext;
- public LinkButton btnLast;
- public Label lblCurrentPage;
- public Label lblPageCount;
- public Label lblRecordCount;
- public TextBox txtIndex;
- public int PageCount,RecordCount;
- private void Page_Load(Object sender, EventArgs e)
- {
- if(!IsPostBack)
- {
- OleDbConnection MyConnection =new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("candsql.mdb"));
- OleDbDataAdapter myCommand=new OleDbDataAdapter("SELECT id,typename FROM bb ",MyConnection);
- DataSet ds= new DataSet();
- myCommand.Fill(ds,"bb");
- DropDownList2.DataSource = ds.Tables["bb"].DefaultView;
- DropDownList2.DataTextField = "typename";
- DropDownList2.DataValueField = "id";
- DropDownList2.DataBind();
- DataBind();
- }
- DataBind();
- }
- DataView CreateDataSource()
- {
- OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ Server.MapPath("candsql.mdb"));
- OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from aa WHERE typeid="+ DropDownList2.SelectedItem.Value+" order by shijian desc", myConnection);
- DataSet ds = new DataSet();
- myCommand.Fill(ds, "aa");
- return ds.Tables["aa"].DefaultView;
- }
- void DataBind()
- {
- DataView source=CreateDataSource();
- if(!IsPostBack)
- {
- RecordCount=source.Count;
- PageCount=RecordCount/MyList.PageSize;
- if((RecordCount%MyList.PageSize)!=0) PageCount++;
- lblRecordCount.Text=RecordCount.ToString();
- lblPageCount.Text=PageCount.ToString();
- lblCurrentPage.Text="1";
- }
- MyList.DataSource = source;
- MyList.DataBind();
- }
- public void MyList_Page(Object sender, DataGridPageChangedEventArgs e)
- {
- //由内置页导航使用。CurrentPageIndex 已设置
- //MyList.CurrentPageIndex = 1;
- MyList.CurrentPageIndex = e.NewPageIndex;
- DataBind();
- }
- public void txtIndex_Changed(Object sender, EventArgs e)
- {
- btnFirst.Enabled=true;
- btnPrev.Enabled=true;
- btnNext.Enabled=true;
- btnLast.Enabled=true;
- //int index=1;
- int index=Int32.Parse(txtIndex.Text.ToString());
- DataView source=CreateDataSource();
- RecordCount=source.Count;
- PageCount=RecordCount/MyList.PageSize+1;
- //PageCount=Int32.Parse(lblPageCount.Text.ToString());
- if(index>=1&&index<=PageCount)
- {
- MyList.CurrentPageIndex=index-1;
- DataBind();
- lblCurrentPage.Text=index.ToString();
- if(index==1)
- {
- btnFirst.Enabled=false;
- btnPrev.Enabled=false;
- }
- else if(index==PageCount)
- {
- btnLast.Enabled=false;
- btnNext.Enabled=false;
- }
- else
- { txtIndex.Text=""; }
- DataBind();
- }
- }
- public void PagerButtonClick(Object sender, CommandEventArgs e)
- {
- btnFirst.Enabled=true;
- btnPrev.Enabled=true;
- btnNext.Enabled=true;
- btnLast.Enabled=true;
- //由外部分页 UI 使用
- DataView source=CreateDataSource();
- RecordCount=source.Count;
- PageCount=RecordCount/MyList.PageSize+1;
- String arg = e.CommandArgument.ToString();
- //PageCount=Int32.Parse(lblPageCount.Text.ToString());
- int pageindex=Int32.Parse(lblCurrentPage.Text.ToString())-1;
- //int pageindex=1;
- switch(arg)
- {
- case "Next":
- if (pageindex < (PageCount - 1))
- pageindex ++;
- else
- pageindex=0;
- break;
- case "Prev":
- if(pageindex> (PageCount-1))
- pageindex=0;
- else if(pageindex> 0)
- pageindex--;
- break;
- case "Last":
- pageindex = (PageCount - 1);
- break;
- case "First":
- pageindex=0;
- break;
- }
- if(pageindex==0)
- {
- btnFirst.Enabled=false;
- btnPrev.Enabled=false;
- }
- else if(pageindex==PageCount-1)
- {
- btnLast.Enabled=false;
- btnNext.Enabled=false;
- }
- MyList.CurrentPageIndex=pageindex;
- DataBind();
- lblCurrentPage.Text=(MyList.CurrentPageIndex+1).ToString();
- }
- public void SubmitBtn_Click(Object sender, EventArgs e)
- {
- {
- OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ Server.MapPath("candsql.mdb"));
- OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from aa where " + DropDownList1.SelectedItem.Value + " like '%" + TextBox1.Text.ToString() + "%'", myConnection);
- DataSet ds = new DataSet();
- myCommand.Fill(ds, "tt");
- MyList.DataSource = ds.Tables["tt"].DefaultView;
- MyList.DataBind();
- }
- }
- public void MyDataGrid_Delete(Object sender, DataGridCommandEventArgs e)
- {
- OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ Server.MapPath("candsql.mdb"));
- String deleteCmd = "DELETE from aa where id = @id";
- OleDbCommand myCommand = new OleDbCommand(deleteCmd, myConnection);
- myCommand.Parameters.Add(new OleDbParameter("@id", OleDbType.Char, 11));
- myCommand.Parameters["@id"].Value = MyList.DataKeys[(int)e.Item.ItemIndex];
- myCommand.Connection.Open();
- try
- {
- myCommand.ExecuteNonQuery();
- }
- catch (OleDbException)
- {
- }
- myCommand.Connection.Close();
- DataBind();
- }
- protected string FormatString(string str)
- {
- str=str.Replace(" "," ");
- str=str.Replace("<","<");
- str=str.Replace(">",">");
- str=str.Replace('n'.ToString(),"<br>");
- return str;
- }
- }
- }