0

我有这样的设计,它在用户控件中

<table>
    <tr>
        <td>
            <asp:DataList ID="dlimgShowCase" runat="server" RepeatDirection="Horizontal" EnableViewState="true">
                <ItemTemplate>
                    <asp:Image ID="imgCatalog" runat="server" Height="292" Width="454" ImageUrl='<%# Eval("path") %>' />
                </ItemTemplate>
            </asp:DataList>
        </td>
    </tr>
    <tr>
        <td>
            <asp:DataList ID="dlPaging" runat="server" class="more_pages_navigation" RepeatDirection="Horizontal"
                Width="100" OnItemCommand="dlPaging_ItemCommand" OnItemDataBound="dlPaging_ItemDataBound"
                EnableViewState="true">
                <ItemTemplate>
                    <li>
                        <asp:LinkButton ID="lnkbtnPaging" runat="server" CommandArgument='<%# Eval("PageIndex") %>'
                            CommandName="Paging" Text='<%# Eval("PageText") %>' Style="text-align: center"
                            OnClick="lnkbtnPaging_Click">   </asp:LinkButton>
                    </li>
                </ItemTemplate>
            </asp:DataList>
        </td>
    </tr>
</table>

我的 C# 代码是

 if (!IsPostBack)
        {
            BindDataItems();              
        }    



 /// <summary>
    /// Binding Images List
    /// </summary>
    private void BindDataItems()
    {
        // If the DataSource Tables are greater than 1            
        try
        {

            if (Cache["DataShowcaseImages"] == null)
                Cache["DataShowcaseImages"] = DataSource.Tables[0];

            objPagedDataSourceCatalogList.DataSource = ((DataTable)(Cache["DataShowcaseImages"])).DefaultView;
            objPagedDataSourceCatalogList.AllowPaging = true;
            objPagedDataSourceCatalogList.PageSize = PageSize;
            objPagedDataSourceCatalogList.CurrentPageIndex = CurrentPage;
            ViewState["TotalPages"] = objPagedDataSourceCatalogList.PageCount;
            dlimgShowCase.DataSource = objPagedDataSourceCatalogList;
            dlimgShowCase.DataBind();
            performPaging();  // This method bind my second grid,, with page numbers
        }
        catch (Exception)
        {

            throw;
        }


    }

我的分页 itemcommand 事件是

 protected void dlPaging_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName.Equals("Paging"))
        {
            CurrentPage = Convert.ToInt16(e.CommandArgument.ToString());
            BindDataItems();
        }
    }

但我不知道为什么项目命令事件没有引发?谁能帮我解决这个问题?

4

1 回答 1

1

也许您没有将实际分配DataSourceDataList,请改用这段代码:

objPagedDataSourceCatalogList.DataSource = ((DataTable)(Cache["DataShowcaseImages"])).DefaultView;
objPagedDataSourceCatalogList.AllowPaging = true;
objPagedDataSourceCatalogList.PageSize = PageSize;
objPagedDataSourceCatalogList.CurrentPageIndex = CurrentPage;
ViewState["TotalPages"] = objPagedDataSourceCatalogList.PageCount;
dlimgShowCase.DataSource = objPagedDataSourceCatalogList.DataSource;
dlimgShowCase.DataBind();
于 2012-11-23T07:01:44.367 回答