Design code :-
<asp:Repeater ID="rptMain" OnItemDataBound="Repeater1_ ItemDataBound" runat="server">
<ItemTemplate>
<h1><%#Eval("Title") %></h1>
<asp:HiddenField ID="hdnparentid" Value='<%#Eval("ID") %>' runat="server" />
<asp:Repeater ID="rptChild" runat="server">
<ItemTemplate>
<asp:Literal ID="ltrchildbody" Text='<%#Eval("Body") %>' runat="server"></asp:Literal>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
Cs code:-
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType==ListItemType. AlternatingItem)
{
HiddenField hdnid = (HiddenField)e.Item. FindControl("hdnparentid");
Repeater rptchild = (Repeater)e.Item.FindControl(" rptChild");
if (rptchild != null)
{
using (SPSite site = new SPSite(SPContext.Current.Site. ID))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists.TryGetList(" DiscussionList");
if (list != null)
{
SPFolder t = list.GetItemById(Convert. ToInt32(hdnid.Value)).Folder;
SPQuery q = new SPQuery();
q.Folder = t;
SPListItemCollection res = list.GetItems(q);
DataTable dt = new DataTable();
dt = res.GetDataTable();
rptchild.DataSource = dt;
rptchild.DataBind();
}
}
}
}
}
}
public void GetDisscussionTitles()
{
using (SPSite site = new SPSite(SPContext.Current.Site. ID))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists.TryGetList(" DiscussionList");
if (list != null)
{
// Empty Query is passed to get only the discussion topics
SPListItemCollection itemColl = list.GetItems(new SPQuery());
DataTable dtmain = itemColl.GetDataTable();
rptMain.DataSource = dtmain;
rptMain.DataBind();
}
}
}
}
No comments:
Post a Comment