【问题标题】:Data pager is not beign displayed数据寻呼机未显示
【发布时间】:2013-03-23 06:29:11
【问题描述】:

大家好,这是我的产品展示页面。我在其中包含了 Datapager 控件。 所有产品都显示在单个页面中...但没有显示用于在页面之间导航的分页器控件

这是我的代码....需要帮助来修复此代码

         <asp:ListView runat="server" ID="listView" GroupItemCount="4">
        <LayoutTemplate>
            <div style="width: 650px;">
                <asp:PlaceHolder runat="server" ID="groupPlaceHolder" />
            </div>
        </LayoutTemplate>
        <GroupTemplate>
            <div style="clear: both;">
                <asp:PlaceHolder runat="server" ID="itemPlaceHolder" />
            </div>
        </GroupTemplate>
        <ItemTemplate>
            <div class="productItem">
                <img src='<%# Eval("p_location") %>' height="120" width="120" alt="Not found" />
                <div>
                    <b>
                        <%# Eval("p_name") %></b></div>
                <div>
                    Price: $<%# Eval("p_price") %></div>

            </div>
        </ItemTemplate>
        <ItemSeparatorTemplate>
            <div class="itemSeparator">
            </div>
        </ItemSeparatorTemplate>
        <GroupSeparatorTemplate>
            <div class="groupSeparator">
            </div>
        </GroupSeparatorTemplate>           
    </asp:ListView>
    <div class="datapager">
        <asp:DataPager ID="DataPager1" PageSize="8" PagedControlID="listView" runat="server">
            <Fields>
                <asp:NextPreviousPagerField ButtonType="Button" />
            </Fields>
        </asp:DataPager>
    </div>

CodeBehind c#:

     protected void Page_Load(object sender, EventArgs e)
    {
    SqlConnection conn = new SqlConnection("ConnectionString");
    conn.Open();
    SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM p_detail", conn);
    DataTable dt = new DataTable();
    da.Fill(dt);
    conn.Close();
    listView.DataSource = dt;
    listView.DataBind();
   }

【问题讨论】:

  • 是完全不显示数据还是仅在您单击页面时显示数据?
  • 它在单个页面中显示所有数据,但不显示分页器控件以在页面之间导航

标签: c# asp.net logic


【解决方案1】:

您需要为该列表视图创建一个事件。
1.进入listview属性
2. 双击名为“PagePropertyChanging”的事件。这将创建一个事件,例如 onpagepropertieschanging="ListView_PagePropertiesChanging"
3.源码

protected void ListView_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)

{
    DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
    ListView.DataSource = dt;
    ListView.DataBind();
}

【讨论】:

  • 好的。你有多少行,显示了多少页?
  • 我的表中有 16 行......它显示了所有产品......这是我找到的代码 First 上一个 下一个 最后 在我的页面源代码...
  • 这应该可以完成工作。您可以尝试删除您的 。只需要 layout 和 itemtemplate
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多