简体   繁体   English

DataList ItemCommand在ASP.NET C#中让我感到困惑吗?

[英]DataList ItemCommand Messing me in asp.net C#?

I had my design like this which is in a user control as 我有这样的设计,它在用户控件中

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

and my C# Code is 我的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;
        }


    }

and my paging itemcommand event is 我的分页itemcommand事件是

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

But i dont know why the hell the item command event is not raising? 但是我不知道为什么项目命令事件没有发生? Could anyone help me out in this? 有人可以帮我吗?

Perhaps you are not assigning the actual DataSource to DataList , use this piece of code instead: 也许您没有将实际的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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM