Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 根据所选记录从中继器控件获取数据_Asp.net_Repeater - Fatal编程技术网

Asp.net 根据所选记录从中继器控件获取数据

Asp.net 根据所选记录从中继器控件获取数据,asp.net,repeater,Asp.net,Repeater,大家好,我的asp.net网页中有一个repeater控件。我想从中继器控件中选择月份,从该月份的基础上,我想得到我在该月份发布的所有数据,这里是中继器控件的源代码 <asp:Repeater ID="Repeater1" runat="server" onitemcommand="Repeater1_ItemCommand"> <ItemTemplate> <ul class="

大家好,我的asp.net网页中有一个repeater控件。我想从中继器控件中选择月份,从该月份的基础上,我想得到我在该月份发布的所有数据,这里是中继器控件的源代码

 <asp:Repeater ID="Repeater1" runat="server" 
                onitemcommand="Repeater1_ItemCommand">

            <ItemTemplate>
            <ul class="archive">
            <li><a href="#">
                 <%#Eval("mnth") %> 
            &nbsp; <%#Eval("yr") %><span>(<%#Eval("totalcount") %>)</span>
                <%--<asp:Label ID="Label6" runat="server" Text="<%#Eval("mnth") %>">&nbsp; 
                    <asp:Label ID="Label8" runat="server" Text="<%#Eval("yr") %>"></asp:Label><span> ( 
                    <asp:Label ID="Label7" runat="server" Text="<%#Eval("totalcount") %>"></asp:Label> ) </span> </a></li>--%>
              </ul>
            </ItemTemplate>

            </asp:Repeater>
这是我正在用的桌子

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[BlogPost](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Title] [varchar](500) NULL,
    [Blogpost] [nvarchar](max) NULL,
    [Paramlink] [varchar](500) NULL,
    [PostDate] [datetime] NULL,
    [IsActive] [int] NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

现在,根据所选月份,我想获得我在该月发布的数据,请告诉我我必须在哪个事件上工作

您使用两个中继器父级和子级 在父转发器中,将一个方法附加到OnItemDataBound事件,并在该方法中找到嵌套转发器并根据月份绑定数据

示例(.aspx):


}使用这种方法。在中继器内放置一个链接按钮(如下示例):


请指定有关要从中提取的表的信息data@Rony请检查我编辑我的问题添加我的table@AzadChohan-使用带有隐藏字段的ID。。。。
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[BlogPost](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Title] [varchar](500) NULL,
    [Blogpost] [nvarchar](max) NULL,
    [Paramlink] [varchar](500) NULL,
    [PostDate] [datetime] NULL,
    [IsActive] [int] NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO
<asp:Repeater ID="ParentRepeater" runat="server" OnItemDataBound="ItemBound">
<ItemTemplate>
    <!-- Repeated data -->
<asp:Label id="monthlabel" Text='<%# DataBinder.Eval(Container.DataItem, "Rating") %>' Runat="server"/>
    <asp:Repeater ID="ChildRepeater" runat="server">
        <ItemTemplate>
            <!-- Nested repeated data -->
        </ItemTemplate>
    </asp:Repeater>
</ItemTemplate>
    protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
    ParentRepeater.DataSource = ...;
    ParentRepeater.DataBind();
}}

protected void ItemBound(object sender, RepeaterItemEventArgs args)
{
if (args.Item.ItemType == ListItemType.Item || args.Item.ItemType == ListItemType.AlternatingItem)
{
var Monthname =((Label)e.Item.FindControl("monthlabel")).Text
    Repeater childRepeater = (Repeater)args.Item.FindControl("ChildRepeater");
    childRepeater.DataSource = ...;
    childRepeater.DataBind();
}
<asp:Repeater ID="Repeater1" runat="server">

    <ItemTemplate>
        <ul class="archive">
            <li>
                <asp:LinkButton runat="server" Text='<%#Eval("mnth") %>' CommandArgument='<%#Eval("mnth") %>' OnCommand="OnMonthSelected"></asp:LinkButton>
            </li>
        </ul>
    </ItemTemplate>

</asp:Repeater>
protected void OnMonthSelected(object sender, CommandEventArgs e)
{
    int month = Convert.ToInt32(e.CommandArgument);

    //get blog posts for month
}