Reusing ItemTemplates

  • Thread starter Thread starter Jonathan Wood
  • Start date Start date
J

Jonathan Wood

My Web application displays some data-driven tables using ItemTemplates.

The tables are on different pages and will be bound to different SQL
statements. However, I want table items to appear exactly the same in all
tables.

Is there anyway to create an ItemTemplate and then reuse that in different
tables on different pages?

Thanks.

Jonathan
 
Yes. You can create your template in a .ascx file like this:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="myItemTemplate"
%>

<div class="ListGridCommandItem">
<div style="float: left; margin-right: 20px">
<asp:LinkButton ID="lnbAddRecord" runat="server"
CommandName="InitInsert">
<img alt="" runat="server"
src="~/Images/GridEditing/AddRecord.gif"/>
Add new
</asp:LinkButton>
</div>
<div style="float: left; width: 100%; margin-left: -100%">
&nbsp;
</div>
<div style="float: right; margin-left: 20px;">
<asp:LinkButton ID="lnbRefreshRecords" runat="server"
CommandName="RebindGrid">
<img alt="" runat="server"
src="~/Images/GridEditing/Refresh.gif"/>
Refresh
</asp:LinkButton>
</div>
<div style="float: right; margin-left: 10px;">
<asp:LinkButton ID="lnbExportToWord" runat="server"
CommandName="ExportWord">
<img alt="" runat="server" src="~/Images/GridEditing/Word.jpg"/>
Export to Word
</asp:LinkButton>
</div>
<div style="float: right;">
<asp:LinkButton ID="lnbExportToExcel" runat="server"
CommandName="ExportExcel">
<img alt="" runat="server"
src="~/Images/GridEditing/Excel.jpg"/>
Export to Excel
</asp:LinkButton>
</div>
</div>


And use it like this:

myListView.ItemTemplate = LoadTemplate("myItemTemplate.ascx");

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Jonathan Wood said:
My Web application displays some data-driven tables using ItemTemplates.

The tables are on different pages and will be bound to different SQL
statements. However, I want table items to appear exactly the same in all
tables.

Is there anyway to create an ItemTemplate and then reuse that in different
tables on different pages?

Thanks.

Jonathan


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4080 (20090515) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4080 (20090515) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
Thanks. May I ask what "myItemTemplate" refer to here (in the inherits
property for the control)?

Jonathan

Eliyahu Goldin said:
Yes. You can create your template in a .ascx file like this:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="myItemTemplate"
%>

<div class="ListGridCommandItem">
<div style="float: left; margin-right: 20px">
<asp:LinkButton ID="lnbAddRecord" runat="server"
CommandName="InitInsert">
<img alt="" runat="server"
src="~/Images/GridEditing/AddRecord.gif"/>
Add new
</asp:LinkButton>
</div>
<div style="float: left; width: 100%; margin-left: -100%">
&nbsp;
</div>
<div style="float: right; margin-left: 20px;">
<asp:LinkButton ID="lnbRefreshRecords" runat="server"
CommandName="RebindGrid">
<img alt="" runat="server"
src="~/Images/GridEditing/Refresh.gif"/>
Refresh
</asp:LinkButton>
</div>
<div style="float: right; margin-left: 10px;">
<asp:LinkButton ID="lnbExportToWord" runat="server"
CommandName="ExportWord">
<img alt="" runat="server"
src="~/Images/GridEditing/Word.jpg"/>
Export to Word
</asp:LinkButton>
</div>
<div style="float: right;">
<asp:LinkButton ID="lnbExportToExcel" runat="server"
CommandName="ExportExcel">
<img alt="" runat="server"
src="~/Images/GridEditing/Excel.jpg"/>
Export to Excel
</asp:LinkButton>
</div>
</div>


And use it like this:

myListView.ItemTemplate = LoadTemplate("myItemTemplate.ascx");

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Jonathan Wood said:
My Web application displays some data-driven tables using ItemTemplates.

The tables are on different pages and will be bound to different SQL
statements. However, I want table items to appear exactly the same in all
tables.

Is there anyway to create an ItemTemplate and then reuse that in
different tables on different pages?

Thanks.

Jonathan


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4080 (20090515) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4080 (20090515) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
Thanks. May I ask what "myItemTemplate" refer to here (in the inherits
property for the control)?

Jonathan

Eliyahu Goldin said:
Yes. You can create your template in a .ascx file like this:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="myItemTemplate"
%>

<div class="ListGridCommandItem">
<div style="float: left; margin-right: 20px">
<asp:LinkButton ID="lnbAddRecord" runat="server"
CommandName="InitInsert">
<img alt="" runat="server"
src="~/Images/GridEditing/AddRecord.gif"/>
Add new
</asp:LinkButton>
</div>
<div style="float: left; width: 100%; margin-left: -100%">
&nbsp;
</div>
<div style="float: right; margin-left: 20px;">
<asp:LinkButton ID="lnbRefreshRecords" runat="server"
CommandName="RebindGrid">
<img alt="" runat="server"
src="~/Images/GridEditing/Refresh.gif"/>
Refresh
</asp:LinkButton>
</div>
<div style="float: right; margin-left: 10px;">
<asp:LinkButton ID="lnbExportToWord" runat="server"
CommandName="ExportWord">
<img alt="" runat="server"
src="~/Images/GridEditing/Word.jpg"/>
Export to Word
</asp:LinkButton>
</div>
<div style="float: right;">
<asp:LinkButton ID="lnbExportToExcel" runat="server"
CommandName="ExportExcel">
<img alt="" runat="server"
src="~/Images/GridEditing/Excel.jpg"/>
Export to Excel
</asp:LinkButton>
</div>
</div>


And use it like this:

myListView.ItemTemplate = LoadTemplate("myItemTemplate.ascx");

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Jonathan Wood said:
My Web application displays some data-driven tables using ItemTemplates.

The tables are on different pages and will be bound to different SQL
statements. However, I want table items to appear exactly the same in all
tables.

Is there anyway to create an ItemTemplate and then reuse that in
different tables on different pages?

Thanks.

Jonathan


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4080 (20090515) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4080 (20090515) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
That's the name of the class in code-behind. I don't think you need to worry
about it in a template. It is there because you start it as a user control.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Jonathan Wood said:
Thanks. May I ask what "myItemTemplate" refer to here (in the inherits
property for the control)?

Jonathan

Eliyahu Goldin said:
Yes. You can create your template in a .ascx file like this:

<%@ Control Language="C#" AutoEventWireup="true"
Inherits="myItemTemplate" %>

<div class="ListGridCommandItem">
<div style="float: left; margin-right: 20px">
<asp:LinkButton ID="lnbAddRecord" runat="server"
CommandName="InitInsert">
<img alt="" runat="server"
src="~/Images/GridEditing/AddRecord.gif"/>
Add new
</asp:LinkButton>
</div>
<div style="float: left; width: 100%; margin-left: -100%">
&nbsp;
</div>
<div style="float: right; margin-left: 20px;">
<asp:LinkButton ID="lnbRefreshRecords" runat="server"
CommandName="RebindGrid">
<img alt="" runat="server"
src="~/Images/GridEditing/Refresh.gif"/>
Refresh
</asp:LinkButton>
</div>
<div style="float: right; margin-left: 10px;">
<asp:LinkButton ID="lnbExportToWord" runat="server"
CommandName="ExportWord">
<img alt="" runat="server"
src="~/Images/GridEditing/Word.jpg"/>
Export to Word
</asp:LinkButton>
</div>
<div style="float: right;">
<asp:LinkButton ID="lnbExportToExcel" runat="server"
CommandName="ExportExcel">
<img alt="" runat="server"
src="~/Images/GridEditing/Excel.jpg"/>
Export to Excel
</asp:LinkButton>
</div>
</div>


And use it like this:

myListView.ItemTemplate = LoadTemplate("myItemTemplate.ascx");

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Jonathan Wood said:
My Web application displays some data-driven tables using ItemTemplates.

The tables are on different pages and will be bound to different SQL
statements. However, I want table items to appear exactly the same in
all tables.

Is there anyway to create an ItemTemplate and then reuse that in
different tables on different pages?

Thanks.

Jonathan


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4080 (20090515) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4080 (20090515) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4088 (20090519) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4088 (20090519) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
That's the name of the class in code-behind. I don't think you need to worry
about it in a template. It is there because you start it as a user control.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Jonathan Wood said:
Thanks. May I ask what "myItemTemplate" refer to here (in the inherits
property for the control)?

Jonathan

Eliyahu Goldin said:
Yes. You can create your template in a .ascx file like this:

<%@ Control Language="C#" AutoEventWireup="true"
Inherits="myItemTemplate" %>

<div class="ListGridCommandItem">
<div style="float: left; margin-right: 20px">
<asp:LinkButton ID="lnbAddRecord" runat="server"
CommandName="InitInsert">
<img alt="" runat="server"
src="~/Images/GridEditing/AddRecord.gif"/>
Add new
</asp:LinkButton>
</div>
<div style="float: left; width: 100%; margin-left: -100%">
&nbsp;
</div>
<div style="float: right; margin-left: 20px;">
<asp:LinkButton ID="lnbRefreshRecords" runat="server"
CommandName="RebindGrid">
<img alt="" runat="server"
src="~/Images/GridEditing/Refresh.gif"/>
Refresh
</asp:LinkButton>
</div>
<div style="float: right; margin-left: 10px;">
<asp:LinkButton ID="lnbExportToWord" runat="server"
CommandName="ExportWord">
<img alt="" runat="server"
src="~/Images/GridEditing/Word.jpg"/>
Export to Word
</asp:LinkButton>
</div>
<div style="float: right;">
<asp:LinkButton ID="lnbExportToExcel" runat="server"
CommandName="ExportExcel">
<img alt="" runat="server"
src="~/Images/GridEditing/Excel.jpg"/>
Export to Excel
</asp:LinkButton>
</div>
</div>


And use it like this:

myListView.ItemTemplate = LoadTemplate("myItemTemplate.ascx");

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Jonathan Wood said:
My Web application displays some data-driven tables using ItemTemplates.

The tables are on different pages and will be bound to different SQL
statements. However, I want table items to appear exactly the same in
all tables.

Is there anyway to create an ItemTemplate and then reuse that in
different tables on different pages?

Thanks.

Jonathan


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4080 (20090515) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4080 (20090515) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4088 (20090519) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4088 (20090519) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
Back
Top