DataList ItemCommand在asp.net C#中弄乱我?

时间:2012-11-23 06:25:11

标签: c# asp.net datalist

我的设计就是这样的用户控件

<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;
        }


    }

我的分页项目命令事件是

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

但我不知道为什么项目命令事件没有提升?有谁可以帮我解决这个问题?

1 个答案:

答案 0 :(得分:1)

也许你没有将实际的DataSource分配给DataList,而是使用这段代码:

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();