http://www.cnblogs.com/eddie005/archive/2006/08/01/WorkingWithData_ASPNET2.html

解决方案 »

  1.   

    楼主SB,用他妈的繁体,你不会用简体中文啊。装B
      

  2.   

    wangbo456(拼命三郎) 不知道.用繁體請教 問題這也有錯嗎?
    公司要求一定要用繁體..客戶都是外企。要用繁體,這也有錯嗎?
    請你說話..道德...咱們都是文明人..
      

  3.   

    这个视频非常好,入门的:
    http://www.cnblogs.com/thcjp/archive/2007/03/30/523658.html
      

  4.   

    http://www.cnblogs.com/eddie005/archive/2006/08/01/WorkingWithData_ASPNET2.html
    非常好
      

  5.   

    这是我以前练习过的一个例子,测试过的,代码不是很规范. <asp:DataList ID="DataList1" runat="server" OnItemCommand="DataList1_ItemCommand">
                <ItemTemplate>
                     <table cellpadding="0" cellspacing="0" style="width: 400px;">
                      <tr>
                         <td align="left" width="320" style="height: 21px">
                          <asp:LinkButton ID="LinkButton1" runat="server" Font-Size="9pt" Font-Underline="False" Text='<%# DataBinder.Eval(Container.DataItem,"name") %>' ForeColor="Black"></asp:LinkButton></td>
                         <td width="100" style="height: 21px">
                           <asp:Label ID="Label1" runat="server" Font-Size="9pt" Text='<%# DataBinder.Eval(Container.DataItem,"datatime") %>' ForeColor="Black"></asp:Label></td>
                        </tr>
                       </table>
                </ItemTemplate>
     </asp:DataList><table cellpadding="0" cellspacing="0">
                              <tr>
                                <td style="width: 100px">                            
                                    <asp:Label ID="Label5" runat="server" Font-Size="9pt" Text="当前页为 [ ">
                                    </asp:Label><asp:Label ID="Label7" runat="server" Text="1" Font-Size="9pt"></asp:Label>
                                    <asp:Label ID="Label3" runat="server" Font-Size="9pt" Text=" ]"></asp:Label></td>
                                 <td style="width: 40px"><asp:LinkButton ID="LinkButton2" runat="server" Font-Size="9pt" Font-Underline="False" ForeColor="Red" OnClick="LinkButton2_Click">|<<</asp:LinkButton></td>
                                <td style="width: 30px">
                                     <asp:LinkButton ID="LinkButton3" runat="server" Font-Size="9pt" Font-Underline="False" ForeColor="Red" OnClick="LinkButton3_Click"><</asp:LinkButton></td>
                                 <td style="width: 48px">
                                      <asp:LinkButton ID="LinkButton4" runat="server" Font-Size="9pt" Font-Underline="False" ForeColor="Red" OnClick="LinkButton4_Click">></asp:LinkButton></td>
                                <td style="width: 49px">
                                      <asp:LinkButton ID="LinkButton5" runat="server" Font-Size="9pt" Font-Underline="False" ForeColor="Red" OnClick="LinkButton5_Click">>>|</asp:LinkButton></td>
                                <td align="center" style="width: 118px">
                                       <asp:Label ID="Label10" runat="server" Text="总页为 [ " Font-Size="9pt" Width="52px"></asp:Label>
                                       <asp:Label ID="Label2" runat="server" Font-Size="9pt"></asp:Label>
                                       <asp:Label ID="Label4" runat="server" Font-Size="9pt" Text=" ]"></asp:Label></td>
                               </tr>
                          </table>后台代码:GM gm = new GM();
        protected void Page_Load(object sender, EventArgs e)
        {
            //gm.EXECDataList(DataList1, "select * from tb_motif where ElectType=2 ", "id");
            dlBind();
        }
        public void dlBind()
        {
            int curpage = Convert.ToInt32(this.Label7.Text);
            PagedDataSource ps = new PagedDataSource();
            DataSet ds = null;
            ds = gm.ReturnDataSet("select * from tb_motif where ElectType=2 ", "tb_motif");
            ps.DataSource = ds.Tables["tb_motif"].DefaultView;
            ps.AllowPaging = true; //是否可以分页
            ps.PageSize = 10; //显示的数量
            ps.CurrentPageIndex = curpage - 1; //取得当前页的页码
            this.LinkButton3.Enabled = true;
            this.LinkButton4.Enabled = true;
            this.LinkButton5.Enabled = true;
            this.LinkButton2.Enabled = true;
            if (curpage == 1)
            {
                this.LinkButton2.Enabled = false;//不显示第一页按钮
                this.LinkButton3.Enabled = false;//不显示上一页按钮
            }
            if (curpage == ps.PageCount)
            {
                this.LinkButton4.Enabled = false;//不显示下一页
                this.LinkButton5.Enabled = false;//不显示最后一页        }
            this.Label2.Text = Convert.ToString(ps.PageCount);
            this.DataList1.DataSource = ps;
            this.DataList1.DataKeyField = "id";
            this.DataList1.DataBind();
        }
        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
            string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
            Response.Redirect("IntegralEdenNewPage.aspx?id=" + id + "");
        }
        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            this.Label7.Text = "1";
            this.dlBind();
        }
        protected void LinkButton3_Click(object sender, EventArgs e)
        {
            this.Label7.Text = Convert.ToString(Convert.ToInt32(this.Label7.Text) - 1);
            this.dlBind();
        }
        protected void LinkButton4_Click(object sender, EventArgs e)
        {
            this.Label7.Text = Convert.ToString(Convert.ToInt32(this.Label7.Text) + 1);
            this.dlBind();
        }
        protected void LinkButton5_Click(object sender, EventArgs e)
        {
            this.Label7.Text = this.Label2.Text;
            this.dlBind();
        }