Results 1 to 4 of 4

Thread: [RESOLVED] Create Repeater programmatically

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2007
    Posts
    180

    Resolved [RESOLVED] Create Repeater programmatically

    I am trying to create a repeater programmatically and am having trouble figureing out how to put the Eval("column name") code into the template.

    I saw some code that said to use Databinder.Eval(Container.DataItem, "columnname"), but when I do Container. DataItem is not available in the object. I tried renaming the container to cont in the instantiate in sub but that didnt make the other container object available.

    Here is the original code done the normal way.

    Code:
     
           <asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                <div>
                    <strong>Q.</strong><a style="margin-left: 10px;" href='javascript:toggleDiv(<%#Eval("ItemID") %>)'><%#Eval("Question")%></a><br />
                    <div id='<%#Eval("ItemID") %>' class="Answers"><%#Eval("Answer")%></div>
                    </div>
                </ItemTemplate>
            </asp:Repeater>
    Here is the code I have so far

    Code:
      
          Dim faqRepeat As New Repeater
    
          Protected sub page_init(byval...., ...) handles me.init
               faqRepeat.ItemTemplate = New MyTemplate
          end sub
    
            Public Class MyTemplate
                Implements ITemplate
    
                Sub InstantiateIn(ByVal container As Control) _
                    Implements ITemplate.InstantiateIn
    
                    Dim str As String = ""
    
                    str = "<strong>Q.</strong>style='margin-left: 10px;' href='javascript:toggleDiv("
    
                End Sub
            End Class

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Create Repeater programmatically

    Hey,

    Short answer is, I don't think you can.

    Instead, you should use the ItemDataBound Event:

    http://msdn.microsoft.com/en-us/libr...databound.aspx

    of the Repeater. This will allow you to set the values within the Repeater ItemTemplate.

    Hope that helps!!

    Gary

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2007
    Posts
    180

    Re: Create Repeater programmatically

    Hmm.

    Well is there a way to put in a placeholder so I can replace the value? Or would I have to add the template during the databinding and pass the values into class that generates the template?

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Create Repeater programmatically

    Add the template during databinding, assign an event handler to the repeater's ItemDataBound, and in there, do what you were originally doing. Thing is, the inline code is meant as a quick and dirty way to get data into the template. But you're going down the full-control route of generating repeaters, so there's going to be absolutely no replacement.

    You also can't add an eval to the placeholder generated dynamically and hope that it'll get replaced Anything that you put in there becomes 'source code' to be generated as HTML to the user's browser, there is no second-pass execution.

Posting Permissions

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



Click Here to Expand Forum to Full Width