zoukankan      html  css  js  c++  java
  • Asp.Net:Repeater 详情 备用

    页面


    repeator就想for循环一样,没有编辑模板,有删除delete和详情detail模板

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="PersonSpecialList.aspx.cs"
        Inherits="UI_ColliSearch_PersonSpecialList" %>
    
    <%@ Register Assembly="WebPageContorl" Namespace="WebPageContorl" TagPrefix="cc1" %>   //引入分页组件
    <!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 runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
            <asp:ImageButton ID="ibtnAdd" runat="server" ImageUrl="~/image/button_35.jpg" OnClick="ibtn_Click"
                Style="height: 21px" />
        </div>
        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1" OnItemCommand="Repeater1_ItemCommand">
            <HeaderTemplate>
                <table>
                    <tr>
                        <td>
                            序号
                        </td>
                        <td>
                            名字
                        </td>
                        <td>
                            性别
                        </td>
                        <td>
                            身份证号
                        </td>
                        <td>
                            操作
                        </td>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <%#Container.ItemIndex+1 %>
                    </td>
                    <td>
                        <%#DataBinder.Eval(Container.DataItem, "Name")%>
                    </td>
                    <td>
                        <%#SelfConvert(Eval("Sex", "{0}"))%>
                    </td>
                    <td>
                        <asp:Label ID="PerIdNumber" runat="server" Text='<%#Eval("PerIdNumber")%>'></asp:Label>
                    </td>
                    <td>
                        <asp:ImageButton ID="ibtnSearch" runat="server" ImageUrl="~/image/page_ck.png" CommandName="Search"
                            CommandArgument='<%# Eval("PopulationID") %>' />
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table></FooterTemplate>
        </asp:Repeater>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetPageList"
            TypeName="BLL.Info_RegisteredPopulationBLL">
            <SelectParameters>
                <asp:Parameter DefaultValue="1" Name="pageIndex" Type="Int32" />
                <asp:Parameter DefaultValue="12" Name="pageSize" Type="Int32" />
                <asp:Parameter DefaultValue="" Name="name" Type="String" />
                <asp:Parameter Direction="Output" Name="pageCount" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <div id="mypage" runat="server">
            <cc1:WebPager ID="WebPager2" runat="server" AlwaysShow="True" BorderStyle="None"
                CssClass="paginator" CurrentPageButtonClass="cpb" CustomInfoHTML="当前第%CurrentPageIndex%页,共%PageCount%页/每页%PageSize%条,总记录数:%RecordCount%"
                CustomInfoTextAlign="Right" FirstPageText="首页" HorizontalAlign="Left" LastPageText="尾页"
                NextPageText="下一页" PrevPageText="上一页" ShowPageIndexBox="Never" Wrap="False" ShowCustomInfoSection="Left"
                OnPageChanged="WebPager2_PageChanged" PageSize="12">
            </cc1:WebPager>
        </div>
        <div style="display: none;">
            <asp:Label ID="lPageIndex" runat="server" Text="0"></asp:Label>
            <asp:Label ID="lPageSize" runat="server" Text="0"></asp:Label>
        </div>
        </form>
    </body>
    </html>
    
    

    项目模板绑定


     <td>
                        <%#Container.ItemIndex+1 %>      //序号,分页后也是从1开始
                    </td>
                    <td>
                        <%#DataBinder.Eval(Container.DataItem, "Name")%>//绑定全写
                    </td>
                    <td>
                        <%#SelfConvert(Eval("Sex", "{0}"))%>                 //绑定后台对应方法
                    </td>
                    <td>
                        <asp:Label ID="PerIdNumber" runat="server" Text='<%#Eval("PerIdNumber")%>'></asp:Label>//绑定Eval缩写  单引号  服务器空间
                    </td>
                    <td>
                        <asp:ImageButton ID="ibtnSearch" runat="server" ImageUrl="~/image/page_ck.png" CommandName="Search"
                            CommandArgument='<%# Eval("PopulationID") %>' />
                    </td>
    

    后台代码

    public partial class UI_ColliSearch_PersonSpecialList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
            if (!IsPostBack)
            {
                WebPager2.RecordCount = 0;
    
            }
        }
    
        //数据总条数赋给分页组件
        protected void ibtn_Click(object sender, ImageClickEventArgs e)
        {
            WebPager2.RecordCount = Info_RegisteredPopulationBLL.GetSpecialCount(TxtName.Text);
            bind();
        }
        protected void WebPager2_PageChanged(object sender, EventArgs e)
        {
            bind();
        }
        //切换页码时,重新绑定数据
        public void bind()
        {
            lPageIndex.Text = (WebPager2.CurrentPageIndex).ToString();
            int pageIndex = Convert.ToInt32(lPageIndex.Text);
            lPageSize.Text = (WebPager2.PageSize).ToString();
            int pageSize = Convert.ToInt32(lPageSize.Text);
            //对数据源进行操作
    
            //复制SelectParameters
            Parameter pageIndexPara = ObjectDataSource1.SelectParameters["pageIndex"];
            Parameter pageSizePara = ObjectDataSource1.SelectParameters["pageSize"];
            Parameter namePara = ObjectDataSource1.SelectParameters["name"];
            Parameter pageCountPara = ObjectDataSource1.SelectParameters["pageCount"];
            //清除原有的SelectParameter
            ObjectDataSource1.SelectParameters.Clear();
            //重新给数据源赋值参数
            pageIndexPara.DefaultValue = lPageIndex.Text;
            pageSizePara.DefaultValue = lPageSize.Text;
            namePara.DefaultValue = TxtName.Text;
            //重新加入新的SelectParameter
            ObjectDataSource1.SelectParameters.Add(pageIndexPara);
            ObjectDataSource1.SelectParameters.Add(pageSizePara);
            ObjectDataSource1.SelectParameters.Add(namePara);
            ObjectDataSource1.SelectParameters.Add(pageCountPara);
            Repeater1.DataBind();
        }
        //转换格式  绑定数据处理函数
        public string SelfConvert(string sex)
        {
            if (sex == "1")
            {
                return "男";
            }
            else if (sex == "2")
            {
                return "女";
            }
            else if (sex == "0")
            {
                return "未知的性别";
            }
            else if (sex == "9")
            {
                return "未说明的性别";
            }
            else
            {
                return "";
            }
    
        }
        //repeator里面任意服务器控件操作都触发ItemCommand。用e.COMMANDnAM和e.argu区分是详情,删除
        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            Label PerIdNumber = e.Item.FindControl("PerIdNumber") as Label;
            Response.Redirect("PersonSpecial.aspx?identityCode=" + PerIdNumber.Text);
        }
    }
    
  • 相关阅读:
    Android中内容观察者的使用 ContentObserver类详解 (转)
    Spinner
    对话框
    ButtonBar 的使用
    EditText/RadioButton/CheckBox使用
    ListView
    PieChar,此代码参考网上
    ComboBox中使用事件
    ColorPicker
    Button
  • 原文地址:https://www.cnblogs.com/leee/p/5395709.html
Copyright © 2011-2022 走看看