Reusing ItemTemplates

Discussion in 'ASP .Net' started by Jonathan Wood, May 15, 2009.

  1. 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
     
    Jonathan Wood, May 15, 2009
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
     
    Eliyahu Goldin, May 17, 2009
    #2
    1. Advertising

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

    Jonathan

    "Eliyahu Goldin" <> wrote in
    message news:...
    > 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" <> wrote in message
    > news:...
    >> 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
    >
    >
    >
     
    Jonathan Wood, May 19, 2009
    #3
  4. 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" <> wrote in message
    news:...
    > Thanks. May I ask what "myItemTemplate" refer to here (in the inherits
    > property for the control)?
    >
    > Jonathan
    >
    > "Eliyahu Goldin" <> wrote in
    > message news:...
    >> 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" <> wrote in message
    >> news:...
    >>> 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
     
    Eliyahu Goldin, May 19, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. aaapaul
    Replies:
    3
    Views:
    430
    Martin Marinov
    Jun 21, 2004
  2. Luis Esteban Valencia

    Datagrid with textboxes on itemtemplates

    Luis Esteban Valencia, Jan 26, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    345
    Luis Esteban Valencia
    Jan 26, 2005
  3. Replies:
    2
    Views:
    2,573
  4. Mr Not So Know It All

    Dynamic Repeater and ItemTemplates

    Mr Not So Know It All, Jan 20, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    888
    Mr Not So Know It All
    Jan 24, 2007
  5. JPabich
    Replies:
    0
    Views:
    763
    JPabich
    Jun 4, 2007
Loading...

Share This Page