Repeater Control Using asp.net Design and C#
Repeater Control Using asp.net Design and C# :
CSS Style:
<style type="text/css">
.divrpt
{
margin: 20px;
font-family: Verdana;
color: Maroon;
font-size: 20px;
}
.rpt
{
border: 1px solid #84945a;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
-khtml-border-radius: 8px;
color: #071019;
padding: 0px;
}
.rpttr
{
border: 2px solid white;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
-khtml-border-radius: 8px;
background-color: #319471;
padding: 0px;
}
.rptSpan
{
color: White;
font-family: Verdana;
}
.rptmar
{
margin: 10px;
color: Maroon;
font-family: Verdana;
}
.rpta
{
color: Maroon;
width: 200px;
height: auto;
text-decoration: underline;
}
.rpta:hover
{
color: #b70b6e;
text-decoration: underline;
}
.rpttdWidth
{
width:100px;
}
.rptTr
{
border-bottom: dashed 1px maroon;
background-color: #F5FAEA;
}
</style>
------------------------------------------------------------
aspx:
<div style="margin: 20px;" align="center">
<div class="divrpt">
<asp:Label ID="lblName" runat="server"></asp:Label>
</div>
<div class="rpt">
<asp:Panel ID="pnl" runat="server">
<asp:Repeater ID="rptList" runat="server">
<HeaderTemplate>
<table>
<tr class="rpttr">
<td align="center">
<span class="rptSpan">Category</span>
</td>
<td>
</td>
<td align="center">
<span class="rptSpan">Product Name</span>
</td>
<td align="center" class="rpttdWidth">
<span class="rptSpan">Priority</span>
</td>
<td align="center" class="rpttdWidth"
<span class="rptSpan">Price </span>
</td>
<td align="center" class="rpttdWidth">
<span class="rptSpan">Quantity</span>
</td>
<td align="center" class="rpttdWidth">
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="rpttr">
<td align="center">
<asp:Label CssClass="rptmar" ID="Label5"
Width="130px" runat="server"
Text='<%#Eval("CategoryName") %>'>
</asp:Label>
</td>
<td align="center">
<img class="rptmar" style="border: solid 1px silver"
alt="Image" src='<%#Eval("ImagePath") %>'
width="100px" height="100px" />
</td>
<td align="center">
<a class="rpta" href="Default.aspx?ID=<%#Eval("Id") %>">
<asp:Label Style="text-decoration: underline"
ID="lblProName" Width="200px" runat="server"
Text='<%#Eval("ProductName") %>'>
</asp:Label>
</a>
<br />
<div style="text-align: left">
<span style="vertical-align: top; font-family: Verdana;
font-size:10px">color:</span>
<asp:Label ID="lblColor" BorderColor="Silver"
BorderWidth="2px" BorderStyle="Solid"
Width="30px" Height="25px" runat="server">
</asp:Label>
</div>
</td>
<td align="center">
<asp:Label CssClass="rptmar" ID="Label1" runat="server"
Text='<%#Eval("Priority") %>'></asp:Label>
</td>
<td align="center" style="font-family: Verdana; color: Red">
<asp:Label Style="margin-left: 10px" ID="Label3" runat="server"
Text="$"></asp:Label>
<asp:Label ID="Label2" runat="server"
Text='<%#Eval("Price")%>'></asp:Label>
</td>
<td style="margin: 10px" align="center">
<asp:Label CssClass="rptmar" ID="Label4" runat="server"
Text='<%#Eval("QuantityRequired") %>'></asp:Label>
</td>
<td style="width: 100px" align="center">
<a class="rptmar" style="background-color: #976ea4;
width: 150px; height: 50px; color: White;
text-decoration: none; border: dashed 1px white"
href="Buy.aspx?BID=<%#Eval("BID") %>">
Buy it!</a>
</td>
</tr>
<tr>
<td colspan="7">
<div style="border: dashed 0.1em maroon">
</div>
</td>
</tr>
</div>
</ItemTemplate>
<FooterTemplate>
<tr class="rpttr">
<td colspan="7" align="center">
<asp:Label Height="30px" Style="color: White;
font-family: Verdana; font-size: 20px"
ID="lblFotterName" runat="server"></asp:Label>
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</div>
</div>
--------------------------------------------------------------------
--------------------------------------------------------------------
aspx:CS
protected void Page_Load(object sender, EventArgs e)
{
View();
ViewName();
}
public void View()
public void View()
{
UserID = Session["UserId"].ToString();
UserID = Session["UserId"].ToString();
Select = "Select * From Product Where UserID='" + UserID + "'";
da = new SqlDataAdapter(Select, Conn);
da.Fill(ds);
rptList.DataSource = ds;
rptList.DataBind();
foreach (RepeaterItem rpt in rptList.Items)
{
Label lbl = (Label)rpt.FindControl("lblColor");
lbl.Attributes.Add("style", "background-color:" +
ds.Tables[0].Rows[rpt.ItemIndex]["Color"] + ";");
}
}
Find Controls:
Find Controls:
public void ViewName()
{
SelectName = "Select
GroomName,BrideName,CONVERT(Varchar(20),WeddingDate,107)
WeddingDate From Registration Where UserId='" + UserID + "'";
GroomName,BrideName,CONVERT(Varchar(20),WeddingDate,107)
WeddingDate From Registration Where UserId='" + UserID + "'";
da = new SqlDataAdapter(SelectName, Conn);
da.Fill(ds, "Name");
GroomName = ds.Tables["Name"].Rows[0]["GroomName"].ToString();
BrideName = ds.Tables["Name"].Rows[0]["BrideName"].ToString();
WedDate = ds.Tables["Name"].Rows[0]["WeddingDate"].ToString();
lblGroomName.Text = GroomName + " & " + BrideName + "'s wedding
on " + WedDate;
Find Controls:
on " + WedDate;
Find Controls:
Label lblFotter = rptList.Controls[rptList.Controls.
Count - 1].FindControl("lblFotterName") as Label;
Count - 1].FindControl("lblFotterName") as Label;
lblFotter.Text = GroomName+" & "+BrideName+" 's";
Footer Design:
Hi,
ReplyDeleteThe Repeater control is used to display a repeated list of items that are bound to the control. The Repeater control may be bound to a database table, an XML file, or
another list of items. Your article very informative, so thanks for sharing your knowledge. There are few other links that also helpful for developers.
http://www.c-sharpcorner.com/uploadfile/prathore/databinding-with-repeater-control-in-Asp-Net-with-C-Sharp/
http://mindstick.com/Articles/72e7a2da-3e10-47eb-8152-5037f5034783/?Repeater%20Control%20in%20ASP%20Net%20with%20C
http://www.codeproject.com/Articles/23452/The-ASP-NET-Repeater-Control