吃螺丝

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

前两天写了个分页的存储过程,今天把前台也写了,代码贴出来给大家分享下,有什么建议请赐教啊~

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CellPadding="4"
                ForeColor="#333333" GridLines="None" Width="650px" OnRowCancelingEdit="GridView1_RowCancelingEdit"
                OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating"
                FooterStyle-BackColor="#990000" Font-Bold="true" DataKeyNames="UserID" OnRowDataBound="GridView1_RowDataBound">
                <%--<PagerTemplate>
                    <asp:LinkButton ID="lbFirst" runat="server" CausesValidation="False">First</asp:LinkButton>
                    <asp:LinkButton ID="lbPrev" runat="server" CausesValidation="False">Prev</asp:LinkButton>
                    <asp:LinkButton ID="lbNext" runat="server" CausesValidation="False">Next</asp:LinkButton>
                    <asp:LinkButton ID="lbLast" runat="server" CausesValidation="False">Last</asp:LinkButton>
                    第<asp:Label ID="lbcurpage" runat="server" Text=""></asp:Label>页
                    共<asp:Label ID="lbpagecount" runat="server" Text=""></asp:Label>页
                    跳到<asp:TextBox ID="tbPage" runat="server" Text="" Width="27px"></asp:TextBox>
                    <asp:LinkButton ID="lbGO" runat="server" CausesValidation="False" Text="GO"></asp:LinkButton>
                </PagerTemplate>--%>
                <Columns>
                    <asp:BoundField DataField="UserID" HeaderText="UserID" ReadOnly="true" />
                    <asp:BoundField DataField="UserName" HeaderText="UserName" />
                    <asp:BoundField DataField="UserPwd" HeaderText="UserPwd" />
                    <%--<asp:BoundField DataField="Gender" HeaderText="Gender" />--%>
                    <asp:TemplateField HeaderText="Gender">
                        <EditItemTemplate>
                            <asp:DropDownList ID="Gender" runat="server">
                            </asp:DropDownList>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <%# Eval("Gender")%>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="PhoneNumber" HeaderText="PhoneNumber" />
                    <asp:BoundField DataField="Address" HeaderText="Address" />
                    <asp:CommandField HeaderText="Select" ShowSelectButton="True" />
                    <asp:CommandField HeaderText="Edit" ShowEditButton="true" />
                    <asp:CommandField HeaderText="Delete" ShowDeleteButton="true" />
                </Columns>
                <RowStyle ForeColor="#000066" />
                <SelectedRowStyle BackColor="#669999" Font-Bold="true" ForeColor="White" />
                <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                <HeaderStyle BackColor="#006699" Font-Bold="true" ForeColor="White" />
            </asp:GridView>
            <asp:LinkButton ID="lbFirst" runat="server" CausesValidation="False"
                onclick="lbFirst_Click">First</asp:LinkButton>
                    <asp:LinkButton ID="lbPrev" runat="server" CausesValidation="False"
                onclick="lbPrev_Click">Prev</asp:LinkButton>
                    <asp:LinkButton ID="lbNext" runat="server" CausesValidation="False"
                onclick="lbNext_Click">Next</asp:LinkButton>
                    <asp:LinkButton ID="lbLast" runat="server" CausesValidation="False"
                onclick="lbLast_Click">Last</asp:LinkButton>
                    第<asp:Label ID="lbcurpage" runat="server" Text=""></asp:Label>页
                    共<asp:Label ID="lbpagecount" runat="server" Text=""></asp:Label>页
                    跳到<asp:TextBox ID="tbPage" runat="server" Text="" Width="27px">1</asp:TextBox>
                    <asp:LinkButton ID="lbGO" runat="server" CausesValidation="False" Text="GO"></asp:LinkButton>

 

以下是后台的代码,

 

///////////////////////一开始绑定数据///////////////////////////////////////////////////////

  protected void GridView_Bind()
    {
        try
        {
            lbcurpage.Text = "1";
            User_ManagementBLL umb = new User_ManagementBLL();
            ArrayList al = umb.GridViewPage(lbcurpage.Text, "2");
            lbpagecount.Text = Convert.ToString(al[1]);
            GridView1.DataSource = (DataSet)al[0];
            GridView1.DataBind();
        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

///////////////////////////////////第一页///////////////////////////////////////////

 protected void lbFirst_Click(object sender, EventArgs e)
    {
        try
        {
            lbcurpage.Text = "1";
            User_ManagementBLL umb = new User_ManagementBLL();
            ArrayList al = umb.GridViewPage(lbcurpage.Text, "2");
            lbpagecount.Text = Convert.ToString(al[1]);
            GridView1.DataSource = (DataSet)al[0];
            GridView1.DataBind();
        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

 

//////////////////////////////上一页////////////////////////////////////////////
    protected void lbPrev_Click(object sender, EventArgs e)
    {
        try
        {
            if (lbcurpage.Text == "1")
            {
                lbcurpage.Text = "1";
                User_ManagementBLL umb = new User_ManagementBLL();
                ArrayList al = umb.GridViewPage(lbcurpage.Text, "2");
                lbpagecount.Text = Convert.ToString(al[1]);
                GridView1.DataSource = (DataSet)al[0];
                GridView1.DataBind();
            }
            else
            {
                lbcurpage.Text = Convert.ToString(Convert.ToInt32(lbcurpage.Text) - 1);
                User_ManagementBLL umb = new User_ManagementBLL();
                ArrayList al = umb.GridViewPage(Convert.ToString(Convert.ToInt32(lbcurpage.Text) - 1), "2");
                lbpagecount.Text = Convert.ToString(al[1]);
                GridView1.DataSource = (DataSet)al[0];
                GridView1.DataBind();
            }

        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

 

///////////////////////////////下一页/////////////////////////////////////////////
    protected void lbNext_Click(object sender, EventArgs e)
    {
        try
        {
            lbcurpage.Text = Convert.ToString(Convert.ToInt32(lbcurpage.Text) + 1);
            User_ManagementBLL umb = new User_ManagementBLL();
            ArrayList al = umb.GridViewPage(Convert.ToString(Convert.ToInt32(lbcurpage.Text) - 1), "2");
            lbpagecount.Text = Convert.ToString(al[1]);
            GridView1.DataSource = (DataSet)al[0];
            GridView1.DataBind();
        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

 

///////////////最后一页//////////////////////////////////////////////////////
    protected void lbLast_Click(object sender, EventArgs e)
    {
        try
        {
            lbcurpage.Text = lbpagecount.Text;
            User_ManagementBLL umb = new User_ManagementBLL();
            ArrayList al = umb.GridViewPage(Convert.ToString(Convert.ToInt32(lbpagecount.Text) - 1), "2");
            lbpagecount.Text = Convert.ToString(al[1]);
            GridView1.DataSource = (DataSet)al[0];
            GridView1.DataBind();
        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

 

///////////////////////////////BLL层//////////////////////////////////////////////

public class User_ManagementBLL
{
 public User_ManagementBLL()
 {
  //
  // TODO: Add constructor logic here
  //
 }

    public ArrayList GridViewPage(string curpage,string pagezize)
    {
        User_ManagementDAL umd = new User_ManagementDAL();
        ArrayList AL = umd.GridViewPageDAL(curpage, pagezize);
        return AL;
    }

 


}

//////////////DAL层//////////////////////////////////////////////////////

public class User_ManagementDAL
{
 public User_ManagementDAL()
 {
  //
  // TODO: Add constructor logic here
  //
 }

    public ArrayList GridViewPageDAL(string curpage,string pagezize)
    {
        string proc_Name = "[Kiros].[Static_User_Page]";
        DataSet DS = new DataSet();
        SqlParameter[] Params = new SqlParameter[3];
        Params[0] = new SqlParameter("@curpageindex", "0");
        Params[1] = new SqlParameter("@pagesize", "2");
        Params[2] = new SqlParameter("@pagecount", SqlDbType.VarChar, 10);
        Params[2].Direction = ParameterDirection.Output;

        MyDBHelper Kiros = new MyDBHelper();
        ArrayList AL = Kiros.Proc_Excute_ArrayList(proc_Name, Params);
        DS = (DataSet)AL[0];
        return AL;
    }
}

 

希望能帮到大家 有什么意见请赐教

posted on 2010-11-29 11:09  吃螺丝  阅读(593)  评论(4编辑  收藏  举报