<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Import Namespace="System.Data"%>
<%@ Page Language="C#" Debug="true" %>
<HTML>
<HEAD>
<script runat="server">
 
private void Page_Load(object send,EventArgs e)
{
int pagecount = 5;
int ctr = Convert.ToInt32(Request["page"]);
int start = ctr*pagecount;
SqlDataAdapter ad = new SqlDataAdapter("Select emp_id,fname,lname from employee","server=localhost;user id=sa;pwd=;database=pubs"); 
    DataTable dt = new DataTable("emp");
    ad.Fill(dt);
    l1.Text = "<table align=center border=2 bordercolor=#ffaaff cellpadding=3 cellspacing=5 width=90%>"+
"<TR Align=center>"+
"<TH width=30% bgColor=#ffaafe>"+
"ID"+
"</TH>"+
"<TH width=30% bgColor=#ffaafe>"+
"First_Name"+
"</TH>"+
"<TH width=30% bgColor=#ffaafe>"+
"Last_Name"+
"</TH>"+
"</TR>";
int rowcount = dt.Rows.Count;
    for(int i=0;i<pagecount;i++)
    {
int j = i+start;
if(j<rowcount) l1.Text = l1.Text+"<TR Align=center><Td width=30% bgColor=#aaaaee>"+dt.Rows[j][0]+"</Td><Td width=30% bgColor=#aaaaee>"+dt.Rows[j][1]+"</Td><Td width=30% bgColor=#aaaaee>"+dt.Rows[j][2]+"</Td></TR>";
    }
    if(rowcount>pagecount)
    {
int cc = 0;
if(rowcount%pagecount==0) cc = rowcount/pagecount;
else cc = rowcount/pagecount+1;
l1.Text = l1.Text + "<tr align=right><td colspan=3>";
for(int ll=1;ll<=cc;ll++)
if(ctr==(ll-1))l1.Text = l1.Text + ll.ToString()+"&nbsp;&nbsp;&nbsp;";
else l1.Text = l1.Text+"<a href=\""+Request.FilePath+"?page="+(ll-1).ToString()+"\">"+ll+"</a>&nbsp;&nbsp;&nbsp;";
l1.Text = l1.Text + "</td></tr><tr align=right><td colspan=3>";
if(ctr==0) {
l1.Text = l1.Text+"First&nbsp;&nbsp;&nbsp;";
l1.Text = l1.Text+"Pre&nbsp;&nbsp;&nbsp;";
l1.Text = l1.Text+"<a href=\""+Request.FilePath+"?page=1\">Next</a>&nbsp;&nbsp;&nbsp";
l1.Text = l1.Text+"<a href=\""+Request.FilePath+"?page="+(cc-1).ToString()+"\">Last</a>";
}
else if(ctr<cc-1)
{
l1.Text = l1.Text+"<a href=\""+Request.FilePath+"\">First</a>&nbsp;&nbsp;&nbsp;";
if(ctr==1)l1.Text = l1.Text+"<a href=\""+Request.FilePath+"\">Pre</a>&nbsp;&nbsp;&nbsp;";
else l1.Text = l1.Text+"<a href=\""+Request.FilePath+"?page="+(ctr-1).ToString()+"\">Pre</a>&nbsp;&nbsp;&nbsp;";
l1.Text = l1.Text+"<a href=\""+Request.FilePath+"?page="+(ctr+1).ToString()+"\">Next</a>&nbsp;&nbsp;&nbsp;";
l1.Text = l1.Text+"<a href=\""+Request.FilePath+"?page="+(cc-1).ToString()+"\">Last</a>";
}
else if(ctr==cc-1)
{
l1.Text = l1.Text+"<a href=\""+Request.FilePath+"\">First</a>&nbsp;&nbsp;&nbsp;";
if(ctr==1)l1.Text = l1.Text+"<a href=\""+Request.FilePath+"\">Pre</a>&nbsp;&nbsp;&nbsp;";
else l1.Text = l1.Text+"<a href=\""+Request.FilePath+"?page="+(ctr-1).ToString()+"\">Pre</a>&nbsp;&nbsp;&nbsp;";
l1.Text = l1.Text+"Next&nbsp;&nbsp;&nbsp;";
l1.Text = l1.Text+"Last";
}
l1.Text = l1.Text +"&nbsp;&nbsp;&nbsp;</td></tr></table>";
}
}
</script>
</HEAD>
<body id="bd1" runat="server">
<form id="f1" Target="_top" name="form" action="htmlformpro.aspx" enctype="UTF7" runat="server">
<asp:Label ID="l1" text="" Runat="server" />
</form>
</body>
</HTML>
如果用SqlDataReader的话,在取数据的地方变通以下就可以了

解决方案 »

  1.   

    文件上传
    加载一个HTML控件(file),ID号为uploadfile1,再把它作为服务器端控件运行:
    调用如下函数。
    void LoadFile()
    {
    uploadfile1.PostedFile.SaveAs(strBaseLocation+now.DayOfYear.ToString()+uploadfile1.PostedFile.ContentLength.ToString()+".jpg");
    //执行上传,并自动根据日期和文件大小不同为文件命名,确保不重复
    //Label1.Text="图片已经上传,文件名为:"+now.DayOfYear.ToString()+uploadfile1.PostedFile.ContentLength.ToString()+".jpg";
      PicPath.Value =now.DayOfYear.ToString()+uploadfile1.PostedFile.ContentLength.ToString()+".jpg";

    pic.Src=strBaseLocation + PicPath.Value ;
    this.Response.Write("<script>window.reload()</script>");
    }
      

  2.   

    绑定:
    BindData()
    {
        DataGrid1.DataSource=oDs.Tables;
        DataGrid1.DataBind();
    }
    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
          DataGrid1.CurrentPageIndex=e.NewPageIndex;
          BindData();
    }
    文件上传:
    用HTML控件(file),记得在"<form >"中加“encType="multipart/form-data"”
      

  3.   

    文件上传嘛,拉一个File Field和一个button就可以了。
    private void Button1_Click(object sender, System.EventArgs e)
    {
    try
    {
    if(File1.PostedFile.ContentLength>0)
    {
    string name = File1.PostedFile.FileName ;
    int i= name.LastIndexOf(".") ;
    string newname =name.Substring(i) ;
    //改变下面的“c:\\"到你想要保存的地址。
    DateTime now=DateTime.Now;
    string strname=now.Year.ToString()+now.Month.ToString()+now.Day.ToString()+File1.PostedFile.ContentLength.ToString()+newname; string path="g:\\UpLoad\\"+strname;
    if(File.Exists(path))
    {
    Label1.Text="此文件名在服务器上已存在!!";
    Label2.Text="";
    Label3.Text="";
    return;
    }
    File1.PostedFile.SaveAs(path);
    //取得上传文件的各种属性。
    Label1.Text="上传文件名:"+File1.PostedFile.FileName;
    Label2.Text="上传文件类型:"+File1.PostedFile.ContentType;
    Label3.Text="上传文件大小:"+File1.PostedFile.ContentLength.ToString();
    }
    }
    catch(Exception err)
    {
    Label1.Text=err.Message;
    Label1.Text=err.Source;
    Label3.Text=err.HelpLink;
    }
    }
      

  4.   

    分页
    1、SqlDataReader可以循环来做,i++,输出fromIndex-toIndex就可以了
    2、webform可以用DataGrid自身的分页功能
    3、WinForm可以用DataSet来作,输出DataSet.DataTable[0].Rows[i],i>=fromIndex,i<=toIndex
    4、也可以用存储过程,建临时表