1,前台页面:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="IConcern.aspx.cs" Inherits="IConcern" %>
<asp:Content ID="Content2" ContentPlaceHolderID="head" Runat="Server">
<link rel="stylesheet" href="css/content.css" type="text/css" />
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<div class="myConcernlist_block"><ul>

<asp:DataList ID="myConcernlist" runat="server" RepeatColumns="6">
<ItemTemplate>
<li>
<div class="myConcernlist_img"><img src="<%#DataBinder.Eval(Container.DataItem, "photo")%>" class="myConcernlist_pic"/></div>
<div class="myConcernlist_name"><asp:Label ID="name" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "truename")%>'></asp:Label></div>
<div class="myConcernlist_consern"><asp:LinkButton ID="Cancel_LinkButton" runat="server" Text="取消"  OnCommand="LinkButton_Command" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"id")%>'></asp:LinkButton></div>
</li>
</ItemTemplate>
</asp:DataList>

</ul></div>

<div class="paging">
当前页是:第<span class="current"><asp:Label ID="currentPage" runat="server" Text="1"></asp:Label></span>页,
总共有<asp:Label ID="total" runat="server"></asp:Label>页
<asp:LinkButton ID="first" runat="server" Text="第一页" OnCommand="LinkBotton_Click" CommandArgument="1" CommandName="first"></asp:LinkButton>
<asp:LinkButton ID="previous" runat="server" Text="上一页" OnCommand="LinkBotton_Click" CommandArgument="1" CommandName="previous"></asp:LinkButton>
<asp:LinkButton ID="next" runat="server" Text="下一页" OnCommand="LinkBotton_Click" CommandArgument="1" CommandName="next"></asp:LinkButton>
<asp:LinkButton ID="last" runat="server" Text="最后页" OnCommand="LinkBotton_Click" CommandArgument="1" CommandName="last"></asp:LinkButton>
</div>

</asp:Content>

2,后台部分:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class IConcern : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            DataList_DataBind();
        }
    }

    public int totalpage;
    protected void DataList_DataBind()
    {
        PagedDataSource ps = new PagedDataSource();
        string sql_ds;
        int curpage = Convert.ToInt32(this.currentPage.Text)-1;
        sql_ds = "select a.*,u.truename,u.photo from individual_attention as a join individual_user as u on a.attention_id=u.id";
        //myConcernlist.DataSource=Maticsoft.DBUtility.DbHelperSQL.Query(sql_ds).Tables[0].DefaultView;
        ps.DataSource = Maticsoft.DBUtility.DbHelperSQL.Query(sql_ds).Tables[0].DefaultView;
        ps.AllowPaging = true;
        ps.PageSize =8;
        ps.CurrentPageIndex = curpage;
        first.Enabled = true;
        previous.Enabled = true;
        next.Enabled = true;
        last.Enabled = true;
        if (ps.CurrentPageIndex == 0)
        {
            this.first.Enabled = false;
            this.previous.Enabled = false;
        }
        if (ps.CurrentPageIndex == ps.PageCount-1)
        {
            this.next.Enabled = false;
            this.last.Enabled = false;
        }
        this.total.Text = Convert.ToString(ps.PageCount);
        totalpage =ps.PageCount;
        myConcernlist.DataSource = ps;
        this.myConcernlist.DataKeyField = "id";
        myConcernlist.DataBind();
    }

    protected void LinkBotton_Click(Object send,CommandEventArgs e)
    {
        string temp;
        temp=e.CommandName;
        if(temp=="first")
        {
            currentPage.Text =Convert.ToString(1);
        }
        if (temp == "previous")
        {
            currentPage.Text = Convert.ToString(Convert.ToInt32(currentPage.Text) - 1);
        }
        if (temp == "next")
        {
            currentPage.Text = Convert.ToString(Convert.ToInt32(currentPage.Text) + 1);
        }
        if (temp == "last")
        {
            currentPage.Text = Convert.ToString(totalpage);
        }
        DataList_DataBind();
    }

    protected void LinkButton_Command(Object sender, CommandEventArgs e)
    {
        Maticsoft.BLL.individual_attention at = new Maticsoft.BLL.individual_attention();
        try
        {
            at.Delete(Convert.ToInt32(e.CommandArgument.ToString()));
            DataList_DataBind();
        }
        catch (Exception ex)
        {
            Console.WriteLine("{0} Exception caught.", ex);
        }
        //test.Text = e.CommandArgument.ToString();
    }

}

相关文章:

  • 2022-01-12
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
相关资源
相似解决方案