Question with HeaderTemplate in DataList

Results 1 to 4 of 4

Thread: Question with HeaderTemplate in DataList

  1. #1
    Join Date
    Dec 1969
    Posts
    189

    Default Question with HeaderTemplate in DataList

    I am trying to use a DataList to display my info. What I want to do is have the Top row of the table be the Table Headers. Then I want to display the records from the Stored Proc. I thought that you put the top portion of the Table in the HeaderTemplate and then the individual rows in the ItemTemplate. When I try this, I get an error that the Table is missing the Table’s closing tag.<BR><BR>Can anyone shed some light?<BR><BR>&#060;HeaderTemplate&#062;<BR>&#060; table cellpadding="4" cellspacing="0" width="590" border="1" bgcolor="White" bordercolor="Gray"&#062;<BR> &#060;tr&#062;<BR> &#060;td align="center" class="GridHeader"&#062;&#060;%=getNextYrMth(0)%&# 062;&#060;/td&#062;<BR> &#060;td align="center" class="GridHeader"&#062;&#060;%=getNextYrMth(1)%&# 062;&#060;/td&#062;<BR> &#060;td align="center" class="GridHeader"&#062;&#060;%=getNextYrMth(2)%&# 062;&#060;/td&#062;<BR> &#060;/tr&#062;<BR>&#060;/HeaderTemplate&#062;<BR><BR>&#060;ItemTemplate&#06 2;<BR>&#060;tr&#062;<BR> &#060;td colspan="15" bgcolor="#f0f8ff"&#062;&#060;%# Container.DataItem("AcctName") %&#062;&#060;/td&#062;<BR> &#060;/tr&#062;<BR> &#060;tr&#062;<BR> &#060;td align="center" class="GridText"&#062;&#060;%# Container.DataItem("Mth0Qty") %&#062;<BR>&#060;%# Container.DataItem("Mth0Total") %&#062;&#060;/td&#062;<BR> &#060;td align="center" class="GridText"&#062;&#060;%# Container.DataItem("Mth1Qty") %&#062;<BR>&#060;%# Container.DataItem("Mth1Total") %&#062;&#060;/td&#062;<BR> &#060;td align="center" class="GridText"&#062;&#060;%# Container.DataItem("Mth2Qty") %&#062;<BR>&#060;%# Container.DataItem("Mth2Total") %&#062;&#060;/td&#062;<BR> &#060;/tr&#062;<BR> &#060;/table&#062;<BR>&#060;/ItemTemplate&#062;<BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    734

    Default RE: Question with HeaderTemplate in DataList

    You have a &#060;/table&#062; within the ItemTemplate which is repeated for each record. Remove HeaderTemplate and put &#060;/table&#062; outside the DataList server control.<BR>You cannot have &#060;%= %&#062; within a databound countrol.<BR>Repeater not DatList is what you need.<BR><BR>&#060;table cellpadding="4" cellspacing="0" width="590" border="1" bgcolor="White" bordercolor="Gray"&#062; <BR> &#060;tr&#062; <BR> &#060;td align="center" class="GridHeader"&#062;&#060;%=getNextYrMth(0)%&# 062;&#060;/td&#062; <BR> &#060;td align="center" class="GridHeader"&#062;&#060;%=getNextYrMth(1)%&# 062;&#060;/td&#062; <BR> &#060;td align="center" class="GridHeader"&#062;&#060;%=getNextYrMth(2)%&# 062;&#060;/td&#062; <BR> &#060;/tr&#062; <BR>&#060;asp:Repeater id="id" runat="server"&#062;<BR>&#060;ItemTemplate&#062; <BR>&#060;tr&#062; <BR> &#060;td colspan="15" bgcolor="#f0f8ff"&#062;&#060;%# Container.DataItem("AcctName") %&#062;&#060;/td&#062; <BR> &#060;/tr&#062; <BR> &#060;tr&#062; <BR> &#060;td align="center" class="GridText"&#062;&#060;%# Container.DataItem("Mth0Qty") %&#062; <BR>&#060;%# Container.DataItem("Mth0Total") %&#062;&#060;/td&#062; <BR> &#060;td align="center" class="GridText"&#062;&#060;%# Container.DataItem("Mth1Qty") %&#062; <BR>&#060;%# Container.DataItem("Mth1Total") %&#062;&#060;/td&#062; <BR> &#060;td align="center" class="GridText"&#062;&#060;%# Container.DataItem("Mth2Qty") %&#062; <BR>&#060;%# Container.DataItem("Mth2Total") %&#062;&#060;/td&#062; <BR> &#060;/tr&#062; <BR>&#060;/ItemTemplate&#062; <BR>&#060;/asp:Repeater&#062;<BR>&#060;/table&#062; <BR><BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    189

    Default RE: Another question with the Repeater

    I put in a Repeater as you suggested but I also want to be able to set the Table (with the column headers) to Visible=False if no records are found.<BR><BR>If I use:<BR>&#060;table id="tblProdVelocity" border="1" runat="server"&#062;<BR><BR>I get the following error:<BR>"Value of type &#039;System.Web.UI.WebControls.Repeater&#039; cannot be converted to &#039;System.Web.UI.HtmlControls.HtmlTableRow&#039 ;"<BR><BR>Any suggestions on how I can set the Table.Visible=False when using a Repeater?<BR><BR>Thanks for the help.

  4. #4
    Join Date
    Dec 1969
    Posts
    734

    Default RE: Another question with the Repeater

    Put the table header within an asp panel and set its visible property to false.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


More ASP Resources

Resources:
-- ASP Articles
-- ASP.NET Information
-- 4Guys ASP F.A.Q.
-- ASPFAQs.com
-- ASP Coding Tips
-- Related Web Technologies
-- User Tips!!
-- JavaScripts


Development Centers
-- HTML5 Development Center
-- Windows Mobile Development Center
-- Android Development Center
-- Cloud Development Project Center


Development Technology
Check out these sites for more articles, tutorials, FAQs, discussions, and code!
-- CodeGuru.com
-- VBForums.com
-- DevX.com
-- Developer.com
-- HTMLGoodies