Repeater应用分页存储过程

来源:互联网 发布:do it move it什么歌 编辑:程序博客网 时间:2024/05/16 15:59

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Hfqk_Manage.aspx.cs" Inherits="ess_bxyw_khda_Hfqk_Manage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>客户档案管理</title>
    <script type="text/javascript" language="javascript" >
    function selectAll(obj)
       {
           var theTable     = obj.parentElement.parentElement.parentElement.parentElement;
           var i;
           var j = obj.parentElement.cellIndex;
       
           for(i=0;i<theTable.rows.length;i++)
           {
               var objCheckBox = theTable.rows[i].cells[j].firstChild;
               if(objCheckBox.checked!=null)objCheckBox.checked = obj.checked;
           }
       }
    </script>
    <style type="text/css">
body
{
width:760px;
/*margin-left:2px;*/
margin-right:auto;
margin-left:auto;
margin-top:0;
margin-bottom:1;
text-align:center;
font-size:9pt;
font-family:宋体;
background-color:#ECF5FF;
}
div
{
padding:0;
margin:0;
}
div.gbColor
{
background-color:Gray;
}
select
{
font-size:10px;
}
span{ margin:0; padding:0}

.verticalSpan{ vertical-align:20%}
.SpanWidth
{
width:20px;
}
label.labelleft
{
margin-right:79px;
}

input
{
margin-left:expression((this.type=="text")?"5px":"");
width:expression((this.type=="text")?"200px":"");
font-family:宋体;
font-size:9pt;
}
input[type="text"]
{
vertical-align:bottom;
margin-left:5px;
width:200px;
}
input[type="submit"]
{
background: #ddebff;
color: #000;
height: 19px;
border: 1px outset #97C7EB;
}
li
{
margin-top:2px;
margin-bottom:2px;
list-style:none;
height:20px;
}

ul{margin:0;padding:0;}

ul.ulspan{ width:40px;float:left;}
ul.ulTopBg{height:23px;background-color:#ECF8FF; margin-bottom:10px; padding-top:2px;}

.TopGuid
{
background: url(../images/location_arrow.gif) #ECF8FF no-repeat left 60%;
text-align: left;
padding-left: 9px;
padding-bottom:2px;
padding-top:6px;
}
.TopDiv1{background-color:#D2E7FC; width:100%; height:1px;font-size:0}
.TopDiv2{background-color:#97C7EB; width:100%;height:3px;font-size:0}
.TopDiv3{background-color:#D2E7FC; width:100%; height:1px;font-size:0;}

.input-button {
background: #fff;
   color:#000;
height: 19px;
border:solid 1px #97C7EB;
line-height:18px;
filter:progid:DXImageTransform.Microsoft.Gradient(gradienttype=0, startcolorstr=#CBE1F7, endcolorstr=#F5F5F5);
}
.textbox{margin:0;}
.InputClass
{
border:0;
border-top-style:none;
border-bottom-style:none;
border-left-style:none;
border-right-style:none;
}

    .table
    {
width:100%;
vertical-align:middle;
border-top:solid 1px black;
border-left:solid 1px black;
}
    .table td
    {
border-right:solid 1px black;
border-bottom:solid 1px black;
line-height:20px;
vertical-align:middle;
}
.table th
{
     border-right:solid 1px black;
     border-bottom:solid 1px black;
     font-size:13px;
     background-color:#A6CBEF;
}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    <div class="TopDiv1"></div>
        <div class="TopGuid">
            <asp:Label ID="Label1" runat="server" Text="保修业务>>专题报告管理"></asp:Label>
        </div>
        <div class="TopDiv2"></div>
        <div class="TopDiv3"></div>
        <div>
            <ul class="ulTopBg">
                <li style="float: left;"><asp:Button ID="BtnAdd" CssClass="input-button" runat="server" Text="新 增" OnClientClick="window.open('Khda_List.aspx');return false;" /></li>
                <li style="float: left; margin-left: 8px"><asp:Button ID="BtnDel" CssClass="input-button" runat="server" Text="删 除" OnClick="BtnDel_Click" OnClientClick="return confirm('确实需要删除吗??')" /></li>
                <li style="float: left; margin-left: 8px"><asp:Button ID="BtnSelect" CssClass="input-button" runat="server" Text="查 询" OnClick="BtnSelect_Click" /></li>
            </ul>
         </div>
    <div>
        <div style="text-align:left;">
            <%--<label style="margin-left:20px"><span class="verticalSpan">查询数据 </span><asp:TextBox ID="TbJddxh" Width="120" runat="server"></asp:TextBox></label>--%>
            <label style="margin-left:20px"><span class="verticalSpan">记账月度 </span></label>
        </div>
        <div style="overflow-x:auto;overflow-y:auto; height:440px; width:100%">
        <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound" OnItemCommand="Repeater1_ItemCommand" OnItemCreated="Repeater1_ItemCreated">
            <HeaderTemplate>
             <table cellspacing="0" style="width:170%; text-align:center" class="table">
             <thead>
             <tr>
                 <th style="width:3%;"><input id="checkAll" type="checkbox" onclick="selectAll(this)" /></th>
                 <th style="width:7%;">编号</th>
                 <th style="width:8%;">姓名</th>
                 <th style="width:10%;">电话</th>
                 <th style="width:19%;">车型</th>
                 <th style="width:6%;">底盘号</th>
                 <th style="width:5%;">购车方式</th>
                 <th style="width:14%;">对公司产品满意度(A质量B价位C交货期)</th>
                 <th style="width:14%;">对公司服务满意度(A售后保养服务B咨询及维护培训C备件供应)</th>
                 <th style="width:14%;">对代理商满意度(A售后保养服务B咨询及维护培训C备件供应)</th>
             </tr>
             </thead>
             <tbody>
            </HeaderTemplate>
            <ItemTemplate>
                <tr onmouseover="if(this.style.backgroundColor!='#b9cddd')this.style.backgroundColor='#CEE3F8'"
                onmouseout="if(this.style.backgroundColor!='#b9cddd')this.style.backgroundColor='#ECF5FF'"
                onclick="var trs = this.parentNode.getElementsByTagName('tr');for( i=0;i<trs.length;i++ )trs[i].style.backgroundColor='#ECF5FF';this.style.backgroundColor='#b9cddd'">
                    <td>
                        <asp:CheckBox ID="CbYxbz" runat="server" />
                    </td>
                    <td>
                    <asp:Label ID="LabLsh" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"lsh") %>'></asp:Label>
                    <asp:Label ID="LabId" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"id") %>'></asp:Label>
                    </td>
                    <td><span><%# DataBinder.Eval(Container.DataItem,"khxm") %></span></td>
                    <td><span><%# DataBinder.Eval(Container.DataItem,"khsj") %></span></td>
                    <td><span><%# DataBinder.Eval(Container.DataItem,"cx") %></span></td>
                    <td><span><%# DataBinder.Eval(Container.DataItem,"dph") %></span></td>
                    <td style="text-align:left;">
                        <asp:RadioButtonList ID="Rbl_gcfs" runat="server" RepeatLayout="Flow">
                        <asp:ListItem Value="A">现款</asp:ListItem>
                        <asp:ListItem Value="B">贷款</asp:ListItem>
                        </asp:RadioButtonList>
                        <asp:Label ID="Lab_gcfs" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"gcfs") %>'></asp:Label>
                    </td>
                    <td style="text-align:left;">
                        <span>A:</span><asp:RadioButtonList ID="Rbl_cpmy1" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
                        <asp:ListItem Value="A">很满意</asp:ListItem>
                        <asp:ListItem Value="B">一般</asp:ListItem>
                        <asp:ListItem Value="C">不满意</asp:ListItem>
                        </asp:RadioButtonList>
                        <br /><span>B:</span><asp:RadioButtonList ID="Rbl_cpmy2" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
                        <asp:ListItem Value="A">很满意</asp:ListItem>
                        <asp:ListItem Value="B">一般</asp:ListItem>
                        <asp:ListItem Value="C">不满意</asp:ListItem>
                        </asp:RadioButtonList>
                        <br /><span>C:</span><asp:RadioButtonList ID="Rbl_cpmy3" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
                        <asp:ListItem Value="A">很满意</asp:ListItem>
                        <asp:ListItem Value="B">一般</asp:ListItem>
                        <asp:ListItem Value="C">不满意</asp:ListItem>
                        </asp:RadioButtonList>
                        <asp:Label ID="Lab_cpmy1" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"cpmy1") %>'></asp:Label>
                        <asp:Label ID="Lab_cpmy2" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"cpmy2") %>'></asp:Label>
                        <asp:Label ID="Lab_cpmy3" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"cpmy3") %>'></asp:Label>
                    </td>
                    <td style="text-align:left;">
                        <span>A:</span><asp:RadioButtonList ID="Rbl_fwmy1" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
                        <asp:ListItem Value="A">很满意</asp:ListItem>
                        <asp:ListItem Value="B">一般</asp:ListItem>
                        <asp:ListItem Value="C">不满意</asp:ListItem>
                        </asp:RadioButtonList>
                        <br /><span>B:</span><asp:RadioButtonList ID="Rbl_fwmy2" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
                        <asp:ListItem Value="A">很满意</asp:ListItem>
                        <asp:ListItem Value="B">一般</asp:ListItem>
                        <asp:ListItem Value="C">不满意</asp:ListItem>
                        </asp:RadioButtonList>
                        <br /><span>C:</span><asp:RadioButtonList ID="Rbl_fwmy3" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
                        <asp:ListItem Value="A">很满意</asp:ListItem>
                        <asp:ListItem Value="B">一般</asp:ListItem>
                        <asp:ListItem Value="C">不满意</asp:ListItem>
                        </asp:RadioButtonList>
                        <asp:Label ID="Lab_fwmy1" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"fwmy1") %>'></asp:Label>
                        <asp:Label ID="Lab_fwmy2" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"fwmy2") %>'></asp:Label>
                        <asp:Label ID="Lab_fwmy3" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"fwmy3") %>'></asp:Label>
                    </td>
                    <td style="text-align:left;">
                        <span>A:</span><asp:RadioButtonList ID="Rbl_dlsmy1" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
                        <asp:ListItem Value="A">很满意</asp:ListItem>
                        <asp:ListItem Value="B">一般</asp:ListItem>
                        <asp:ListItem Value="C">不满意</asp:ListItem>
                        </asp:RadioButtonList>
                        <br /><span>B:</span><asp:RadioButtonList ID="Rbl_dlsmy2" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
                        <asp:ListItem Value="A">很满意</asp:ListItem>
                        <asp:ListItem Value="B">一般</asp:ListItem>
                        <asp:ListItem Value="C">不满意</asp:ListItem>
                        </asp:RadioButtonList>
                        <br /><span>C:</span><asp:RadioButtonList ID="Rbl_dlsmy3" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
                        <asp:ListItem Value="A">很满意</asp:ListItem>
                        <asp:ListItem Value="B">一般</asp:ListItem>
                        <asp:ListItem Value="C">不满意</asp:ListItem>
                        </asp:RadioButtonList>
                        <asp:Label ID="Lab_dlsmy1" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"dlsmy1") %>'></asp:Label>
                        <asp:Label ID="Lab_dlsmy2" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"dlsmy2") %>'></asp:Label>
                        <asp:Label ID="Lab_dlsmy3" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"dlsmy3") %>'></asp:Label>
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
            </tbody>
            </table>
            </FooterTemplate>
        </asp:Repeater>
        </div>
        <div style="padding: 5px; background-color: #dedede">
            <asp:LinkButton ID="Lb_Pre" runat="server" OnClick="Lb_Pre_Click">上一页</asp:LinkButton>
            <asp:LinkButton ID="Lb_Next" runat="server" OnClick="Lb_Next_Click">下一页</asp:LinkButton>  
                <span>转到:</span><asp:TextBox ID="Tb_no" Width="20" runat="server"></asp:TextBox>
            <asp:Button ID="Btn_GoPage" runat="server" Text="Go" Width="20" OnClick="Btn_GoPage_Click" />
             <span>当前页码:<%=ViewState["page"]%></span>
             <span>总页数:<%=Math.Ceiling(Convert.ToInt32(ViewState["total"])/5.0)%></span>
             <span>总记录数:<%=ViewState["total"]%></span>
        </div>
    </div>
    </form>
</body>
</html>

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

public partial class ess_bxyw_khda_Hfqk_Manage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ViewState["page"] = "1";
            ViewState["where"] = "''''";
            string sql1,sql = "exec pagination 'V_hfqk','[id],[lsh], [khxm], [khsj], [cx], [dph], [gcfs], [cpmy1],[cpmy2],[cpmy3],[fwmy1],[fwmy2], [fwmy3], [dlsmy1], [dlsmy2], [dlsmy3]','id',5,";
            sql1 = sql + ViewState["page"];
            sql1 += ",0,0,";
            sql1 += ViewState["where"];
            string sql2 = sql + ViewState["page"] + ",1,0," + ViewState["where"];
            ViewState["total"] = DbOperateClass.DbOperate.GetSelectObj(sql2).ToString();
            Repeater1.DataSource = DbOperateClass.DbOperate.GetDataSet(sql1);
            Repeater1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            ((RadioButtonList)e.Item.FindControl("Rbl_gcfs")).SelectedValue = ((Label)e.Item.FindControl("Lab_gcfs")).Text;
            ((RadioButtonList)e.Item.FindControl("Rbl_cpmy1")).SelectedValue = ((Label)e.Item.FindControl("Lab_cpmy1")).Text;
            ((RadioButtonList)e.Item.FindControl("Rbl_cpmy2")).SelectedValue = ((Label)e.Item.FindControl("Lab_cpmy2")).Text;
            ((RadioButtonList)e.Item.FindControl("Rbl_cpmy3")).SelectedValue = ((Label)e.Item.FindControl("Lab_cpmy3")).Text;
            ((RadioButtonList)e.Item.FindControl("Rbl_fwmy1")).SelectedValue = ((Label)e.Item.FindControl("Lab_fwmy1")).Text;
            ((RadioButtonList)e.Item.FindControl("Rbl_fwmy2")).SelectedValue = ((Label)e.Item.FindControl("Lab_fwmy2")).Text;
            ((RadioButtonList)e.Item.FindControl("Rbl_fwmy3")).SelectedValue = ((Label)e.Item.FindControl("Lab_fwmy3")).Text;
            ((RadioButtonList)e.Item.FindControl("Rbl_dlsmy1")).SelectedValue = ((Label)e.Item.FindControl("Lab_dlsmy1")).Text;
            ((RadioButtonList)e.Item.FindControl("Rbl_dlsmy2")).SelectedValue = ((Label)e.Item.FindControl("Lab_dlsmy2")).Text;
            ((RadioButtonList)e.Item.FindControl("Rbl_dlsmy3")).SelectedValue = ((Label)e.Item.FindControl("Lab_dlsmy3")).Text;
        }
    }
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "up")
        {
           
        }
        if (e.CommandName == "down")
        {
           
        }
    }
    protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
    {

    }

    protected void BtnSelect_Click(object sender, EventArgs e)
    {

    }
    protected void BtnDel_Click(object sender, EventArgs e)
    {

    }
    public void RepeaterBind(string page)
    {
        string sql1, sql = "exec pagination 'V_hfqk','[id],[lsh], [khxm], [khsj], [cx], [dph], [gcfs], [cpmy1],[cpmy2],[cpmy3],[fwmy1],[fwmy2], [fwmy3], [dlsmy1], [dlsmy2], [dlsmy3]','id',5,";
        sql1 = sql + page;
        sql1 += ",0,0,";
        sql1 += ViewState["where"];
        Repeater1.DataSource = DbOperateClass.DbOperate.GetDataSet(sql1);
        Repeater1.DataBind();
    }
    protected void Btn_GoPage_Click(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(Tb_no.Text.Trim()))
            return;
        int page = Convert.ToInt32(Tb_no.Text.Trim());
        if (page < 1 || page > Math.Ceiling(Convert.ToInt32(ViewState["total"]) / 5.0))
            return;
        ViewState["page"] = Tb_no.Text;
        RepeaterBind(ViewState["page"].ToString());
    }
    protected void Lb_Pre_Click(object sender, EventArgs e)
    {
        int page = Convert.ToInt32(ViewState["page"]);
        if (page > 1)
        {
            ViewState["page"] = ((int)(page - 1)).ToString();
            RepeaterBind(ViewState["page"].ToString());
        }
    }
    protected void Lb_Next_Click(object sender, EventArgs e)
    {
        int page = Convert.ToInt32(ViewState["page"]);
        if (page < Math.Ceiling(Convert.ToInt32(ViewState["total"]) / 5.0))
        {
            ViewState["page"] = ((int)(page + 1)).ToString();
            RepeaterBind(ViewState["page"].ToString());
        }
    }
}


分页存储过程:
CREATE PROCEDURE pagination
@tblName varchar(255), -- 表名
@strGetFields varchar(1000) = '*', -- 需要返回的列
@fldName varchar(255)='''', -- 排序的字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@doCount bit = 0, -- 返回记录总数, 非 0 值则返回
@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere varchar(1500) = '''' -- 查询条件 (注意: 不要加 where)
AS
declare @strSQL varchar(5000) -- 主语句
declare @strTmp varchar(110) -- 临时变量
declare @strOrder varchar(400) -- 排序类型
if @doCount != 0
begin
if @strWhere !=''''
   set @strSQL = 'select count(*) as Total from [' + @tblName + '] where '+@strWhere
else
   set @strSQL = 'select count(*) as Total from [' + @tblName + ']'
end--以上代码的意思是如果@doCount传递过来的不是0,就执行总数统计。以下的所有代码都是@doCount为0的情况:
else
begin
if @OrderType != 0
begin --如果@OrderType不是0,就执行降序,这句很重要!
   set @strTmp = '<(select min'
   set @strOrder = ' order by [' + @fldName +'] desc'
end
else
begin
   set @strTmp = '>(select max'
   set @strOrder = ' order by [' + @fldName +'] asc'
end
if @PageIndex = 1
begin --如果是第一页就执行以上代码,这样会加快执行速度
   if @strWhere != '''' set @strSQL = 'select top ' + str(@PageSize) +' '
    +@strGetFields+ 'from [' + @tblName + '] where '
     + @strWhere + ' ' + @strOrder
   else set @strSQL = 'select top ' + str(@PageSize) +' '
    +@strGetFields+ 'from ['+ @tblName + '] '+ @strOrder
end
else
begin--以下代码赋予了@strSQL以真正执行的SQL代码 
   set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+
   ' from ['+ @tblName + '] where [' + @fldName + ']' +
   @strTmp + '(['+ @fldName + '])from (select top ' +
   str((@PageIndex-1)*@PageSize) + ' ['+ @fldName + ']from [' +
   @tblName + ']' + @strOrder + ') as tblTmp)'+ @strOrder
   if @strWhere != ''''
    set @strSQL = 'select top ' + str(@PageSize) +' '+
    @strGetFields+ ' from ['+ @tblName + '] where [' +
    @fldName + ']' + @strTmp + '(['+ @fldName + ']) from (select top ' +
    str((@PageIndex-1)*@PageSize) + ' ['+ @fldName + '] from [' +
    @tblName + '] where ' + @strWhere + ' '+ @strOrder + ') as tblTmp) and ' +
    @strWhere + ' ' + @strOrder
end
end
exec (@strSQL)
GO

 

原创粉丝点击