dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersPhagu Mahato
Matt M
naveensanagasetti
Padma
Amruta
Anil Kumar Pandey
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » Code Snippets » Active Directory

Use Nested Repeater in ASP.NET 2.0 with C#


Posted Date:     Category: Active Directory    
Author: Member Level: Gold    Points: 10



 


The given code is the example of nested repeater in Asp.net 2.0 with C#.

Hereby I have given the code for both HTML file and C# code behind file.

NestedRepeater.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Nestedrepeater.aspx.cs" Inherits="Nestedrepeater" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Nestedrepeater</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
color: #0000FF;
}
a:visited {
color: #0000FF;
}
a:hover {
color: #0000FF;
text-decoration: none;
}
a:active {
color: #0000FF;
}
.basix {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
}
.header1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
color: #006699;
}
.lgHeader1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 18px;
font-weight: bold;
color: #0066CC;
background-color: #CEE9FF;
}
-->
</style>
</head>
<body>
<form id="form1" runat="server">
<br />
<table align="center" border="0" cellpadding="0" cellspacing="0" width="752">
<tr bgcolor="#5482fc">
<td colspan="4">
<img height="1" src="/media/spacer.gif" width="1" /></td>
</tr>
<tr>
<td bgcolor="#5482fc" width="1">
<img alt="Server Intellect" height="1" src="media/spacer.gif" width="1" /></td>
<td width="250">
<a href="http://www.serverintellect.com">
<img alt="Server Intellect" border="0" height="75" src="media/logo.gif" width="250" /></a></td>
<td bgcolor="#3399ff" width="500">
<a href="http://www.serverintellect.com">
<img alt="Server Intellect" border="0" height="75" src="media/headerR1.gif" width="500" /></a></td>
<td bgcolor="#5482fc" width="1">
<img alt="Server Intellect" height="1" src="media/spacer.gif" width="1" /></td>
</tr>
<tr bgcolor="#5482fc">
<td colspan="4">
<img height="1" src="media/spacer.gif" width="1" /></td>
</tr>
</table>
<div>
<br />
<table align="center" bgcolor="#5482fc" border="0" cellpadding="5" cellspacing="1"
width="600">
<tr>
<td align="center" class="lgHeader1" height="50">
To display hierarchical data using nested Repeater Control (C#)</td>
</tr>
</table>
<br />
<br />
<fieldset>
<legend>Nested Repeater</legend>
<table>
<tr>
<td><b>Show the author and his works from the databases of pubs</b></td></tr>
<tr>
<td align="center">
<asp:repeater id="parent" runat="server">
<itemtemplate>
<b><%# DataBinder.Eval(Container.DataItem,"au_lname") %></b><br>
<asp:repeater id="child" datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>' runat="server">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "[\"title\"]")%><br>
</itemtemplate>
</asp:repeater>
</itemtemplate>
</asp:repeater></td></tr>
</table></fieldset>
</div>
<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" width="500">
<tr>
<td align="center" class="basix" height="50">
<strong>Power. Stability. Flexibility.</strong><br />
Hosting from <a href="http://www.serverintellect.com">Server Intellect</a><br />
<br />
For more ASP.NET Tutorials visit <a href="http://www.AspNetTutorials.com">www.AspNetTutorials.com</a></td>
</tr>
</table>
</form>
</body>
</html>


NestedRepeater.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Nestedrepeater : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Create the connection and DataAdapter for the Authors table.
SqlConnection cnn = new SqlConnection("server=(local);database=pubs;uid=sa;pwd=;");
SqlDataAdapter cmd1 = new SqlDataAdapter("select * from authors", cnn);

//Create and fill the DataSet.
DataSet ds = new DataSet();
cmd1.Fill(ds, "authors");

//Create a second DataAdapter for the Titles table.
SqlDataAdapter cmd2 = new SqlDataAdapter("select * from titles,titleauthor,authors where titles.title_id=titleauthor.title_id and authors.au_id=titleauthor.au_id", cnn);
cmd2.Fill(ds, "titles");

//Create the relation bewtween the Authors and Titles tables.
ds.Relations.Add("myrelation",ds.Tables["authors"].Columns["au_id"],ds.Tables["titles"].Columns["au_id"]);

//Bind the Authors table to the parent Repeater control, and call DataBind.
parent.DataSource = ds.Tables["authors"];
Page.DataBind();

//Close the connection.
cnn.Close();

}

}






Did you like this resource? Share it with your friends and show your love!


Responses to "Use Nested Repeater in ASP.NET 2.0 with C#"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Fiinding Difference Between Dates
    Previous Resource: How to draw circle using VB.Net
    Return to Resources
    Post New Resource
    Category: Active Directory


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.