Templates
In this article, We will learn about templates and also how to make project using Repeater
#Templates
Collection of html and web control. We have total 15
templates.
#The names are as follow:
- ItemTemplate
- AlternatingTemplate
- HeaderTemplate
- FooterTemplate
- SeparatorTemplate
- SelectedItemTemplate
- EditItemTemplate
- PagerTemplate
- EmptyDataTemplate
- InsertItemTemplate
- LayoutTemplate
- GroupTemplate
- GroupSeparatorTemplate
- ItemSeparatorTemplate
- EmptyItemTemplate
Note: All templates are always used with composite
data bound control or vice versa.
# Composite Data bound Control
Controls in which inner control, child control or
control under control.
There are 7 Composite Data bound Control :
- Repeater
- Data list
- Grid view
- Detail view
- Form view
- List view
- Data pager
* Repeater
- It is used to display data in single column.
- There is no manipulation (read only).
- No default template
- No paging (not pre-defined paging)
There are 5 templates which apply on Repeater:
ItemTemplate
AlternatingTemplate
HeaderTemplate
FooterTemplate
SeparatorTemplate
# For Repeater
Create new table in vs
Add data in the table
Working With Repeater
Here we will learn How to work with Repeater
# Open new project in Visual Studio
# File > New project> Language C#
# Add
Connection String
* Click
on View > Solution explorer > web.config
<configuration>
<connectionStrings>
<add name="ms" connectionString="server=DESKTOP-I3R20OL\SQLEXPRESS;database=dbemployee;integrated
security= true"/>
</connectionStrings>
<system.web>
|
*Click on website > Add> New item > webform
Click on
toolbox> data>repeater
Select
a1,a2,a3,a4 and copy then
Click on
solution explorer >right click on web app>paste
public partial class WebForm1 : System.Web.UI.Page
{
private void Rep_Bind()
{
SqlDataAdapter adp = new SqlDataAdapter("select * from tbbook", ConfigurationManager.ConnectionStrings["ms"].ConnectionString);
DataSet ds = new DataSet();
adp.Fill(ds);
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
|
SqlDataAdapter
– class of system.data.sqlclient
*SqlDataAdapter= always used with disconnected
approach. It implicit open the connection and close the connection on its own.
*Data Set = collection of tables or array of tables.
We can set the relation. Read write data and xml format.
# Types of DataSet
- Typed dataset
- Untyped dataset
*Typed dataset = It defines the structure at design
time.
Its extension is .xsd
It have better performance bcoz of early bind
concept.
It is mainly used in reports and fixed number of
column operation. Ex reports are end result
*Untyped dataset = It defines the structure at
runtime, It is late bind concept means memory allocation and runtime data is
put at runtime. Therefore slow performance. Column are not fixed.
# Untyped dataset is used :
*Fill method = First open coonection with database
then it will execute query. Then it will fetch data and connection will close.
# In page load event
protected void Page_Load(object sender,
EventArgs e)
{
Rep_Bind();
}
|
# Click on webform > Source
Asp: tag prefix for Microsoft
Asp: - repeater tag name
Item template – it runs up to number of records in
table
Img src = path for image from table.
<tr> - table row
<td> - column table
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<table border="1">
<tr>
<td>
<img src ='<%#Eval("bookimg")%>' height="50" width="50" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
|
# To add description to pics
<b> - For bold writing
<br> - For break
</td>
<td>
<b>Title :</b><%#Eval ("BookTitle") %><br />
<b>Author :</b><%#Eval ("BookAuthor") %><br />
<b>Publisher :</b><%#Eval ("BookPublisher") %><br />
<b>Price :</b><%#Eval ("BookPrice") %><br />
</td>
|
No comments:
Post a Comment