2013-11-22 38 views
0

大家好我在我的asp.net網頁中有一箇中繼器控件。我想從中繼器控制中選擇月份,並從當月的基準中獲取我在該月發佈的所有數據以下是中繼器控制的源代碼。從中繼器控制中獲取數據在所選記錄的基礎上

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

這裏是我用來將Repeater控件綁定

private void BindPostCounts() 
    { 
     SqlCommand cmdBindCounts = new SqlCommand("CountBlogPost_sp", con); 
     cmdBindCounts.CommandType = CommandType.StoredProcedure; 
     SqlDataAdapter daBindCounts = new SqlDataAdapter(cmdBindCounts); 
     DataSet dsBindCount = new DataSet(); 
     daBindCounts.Fill(dsBindCount); 
     Repeater1.DataSource = dsBindCount; 
     Repeater1.DataBind(); 


    } 

的代碼,這是我使用

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 

上現在每月基地選擇我要表得到我在那個月發佈的數據請告訴我哪個事件我必須工作

+0

就請您從中獲取數據表指定信息 –

+0

@Rony請編輯我的問題加我的表 –

+0

@AzadChohan - 使用ID與隱藏字段.... –

回答

0

使用這種方法。把你的中繼器內的LinkBut​​ton(例如波紋管):

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

您使用兩個中繼器pa租金和子女 在父級中繼器中,將方法附加到OnItemDataBound事件和方法中,找到嵌套的中繼器並根據月份綁定數據。

實施例(的.aspx):

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

實施例(的.cs):

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

}

相關問題