简体   繁体   English

与DataPager绑定时,Repeater Onitem命令不会触发。 为什么?

[英]Repeater Onitemcommand won't fire when binded with DataPager. Why?

I'm working with displaying video thumbnails in the repeater control with datapager. 我正在使用datapager在转发器控件中显示视频缩略图。 I recently discovered that the onitemcommand of the repeater control won't fire once it is being bind with the datapager but if you remove the datapager from binding the repeater it works.But I want to use the datapager for the repeater cause I want to set the pagesize in order to display specific number of thumbnails on the repeater. 我最近发现,将中继器控件的onitem命令与datapager绑定后将不会触发,但是如果您从绑定中继器中删除了datapager,它将起作用。但是我想将datapager用于中继器,因为我想设置页面大小,以便在转发器上显示特定数量的缩略图。 How do I make the onitemcommand of the repeater to fire using with datapager?How do I do this in asp.net? 我该如何使中继器的onitem命令与datapager一起使用?如何在asp.net中执行此操作? Pls help...Thankz. 请帮助...谢谢。

Directive: 指示:

<%@ Register Assembly ="DataPagerRepeater" Namespace ="DataPagerRepeater" TagPrefix ="vid"  %>

Here's my HTML source tag of the repeater control with DataPager: 这是DataPager的转发器控件的HTML源代码:

<vid:DataPagerRepeater ID="Repeater1" runat="server" 
                        DataSourceID="SqlDataSource1" onitemcommand="Repeater1_ItemCommand">

                   <HeaderTemplate >
                   <table border ="0" style ="width :350px;" >
                   </HeaderTemplate>

                   <ItemTemplate >
                   <tr>
                   <td style ="border :0px; height :100px; width :350px">
                   <asp:ImageButton ID ="thumb" runat ="server"  style=" margin-right :5px" Width ="120px" Height ="75px" ImageAlign = "Left"  ImageUrl='<%#Eval("Filename","~/Thumbs/{0}") %>' />
                   <asp:Label ID="title" runat ="server"  Text ='<%#Eval("Title") %>' />
                   <br />
                   <asp:Label ID ="artist" runat ="server"  Text ='<%#Eval("Artist") %>' />
                   <br />
                    <asp:Label ID ="view" runat ="server"   Text ='<%#Eval("Views") %> '  />
                  <asp:Label ID ="Label3" runat ="server" Text =" Views" /> 
                    <br />
                   <%--  <asp:Label ID ="fname" runat ="server"  Text ='<%#Eval("VidFname") %>' /> --%>
                   <asp:TextBox ID ="fname" runat ="server"  Text ='<%#Eval("VidFname") %>' />
                     </td>

                      </tr>

                   </ItemTemplate>

                   <%--  
                   <AlternatingItemTemplate >
                   <tr>
                   <td style ="border :0px; height :100px; width :140px">
                    <asp:ImageButton ID ="thumb2" runat ="server" style=" margin-right :5px" Width ="120px" Height ="75px" ImageAlign ="Left" ImageUrl ='<%#Eval("Filename","~/Thumbs/{0}") %>' />
                   <asp:Label ID="title2" runat ="server" Text ='<%#Eval("Title") %>' />
                   <asp:Label ID ="artist2" runat ="server"  style="margin-left :20px" Text ='<%#Eval("Artist") %>' />
                   <asp:Label ID ="view2" runat ="server"  style="margin-left :20px" Text ='<%#Eval("Views") %> ' />
                  <!-- <asp:Label ID ="Label4" runat ="server" Text =" Views" /> -->

                   </td>

                      </tr>

                   </AlternatingItemTemplate>
                  --%>

                   <SeparatorTemplate >
                   <br />
                   </SeparatorTemplate>
                   <FooterTemplate >
                   </table>
                   </FooterTemplate>

</vid:DataPagerRepeater>


<asp:DataPager ID="DataPager1" runat="server" PagedControlID="Repeater1" PageSize="10">
                   <Fields>

          <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />

          <asp:NumericPagerField />

          <asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />

                 </Fields> 
        </asp:DataPager>

It is working indeed! 确实在工作! Add a Linkbutton to fire the ItemCommand: 添加一个Linkbutton来触发ItemCommand:

<ItemTemplate >
    <tr>
        <td style ="border :0px; height :100px; width :350px">
        <asp:ImageButton ID ="thumb" runat ="server"  style=" margin-right :5px" Width ="120px" Height ="75px" ImageAlign = "Left"  ImageUrl='<%#Eval("Filename","~/Thumbs/{0}") %>' />
        <asp:LinkButton ID="LinkButton1" runat="server"
                            CommandName="cmd"
                            CommandArgument='<%# Eval("VidFname") %>' Text="TEST" />

And test in the code: 并在代码中进行测试:

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    if (e.CommandName == "cmd")
    {
        //set a break point in the next line
        string myString = e.CommandName;
    }
}

Edit: Image buttons are like command button and they do fire their own OnCommand instead of repeater's OnItemCommand, so they will not fire repeater's OnItemCommand. 编辑:图像按钮就像命令按钮,它们会触发自己的OnCommand而不是转发器的OnItemCommand,因此它们不会触发转发器的OnItemCommand。 Instead use link button with Image on it: 而是使用上面带有图片的链接按钮:

    <asp:LinkButton ID="LinkButton1" runat="server"
                        CommandName="cmd"
                        CommandArgument='<%# Eval("VidFname") %>' >
            <img src="test.jpg" alt="my cmd" />TEST
    </asp:LinkButton> 

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

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