How do I change or add data to a data repeater and get it to display in ASP.NET

Posted by CowKingDeluxe on Stack Overflow See other posts from Stack Overflow or by CowKingDeluxe
Published on 2010-04-26T19:02:59Z Indexed on 2010/04/26 19:23 UTC
Read the original article Hit count: 178

Here is my code-behind, this adds the "OakTreeName" to the datarepeater. There's about 200 of them.

Dim cmd As New SqlClient.SqlCommand("OakTree_Load", New SqlClient.SqlConnection(ConnStr))
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection.Open()
Dim datareader As SqlClient.SqlDataReader = cmd.ExecuteReader()

OakTree_Thumb_Repeater.DataSource = datareader
OakTree_Thumb_Repeater.DataBind()
cmd.Connection.Close()

Here is essentially what I'd like to do with my markup:

<ContentTemplate>
   <asp:Repeater ID="OakTree_Thumb_Repeater" runat="server">
      <ItemTemplate>
         <asp:ImageButton ImageUrl="<%# Container.DataItem("OakTreeName") %>" AlternateText="" runat="server" />
         <!-- Or I'd like to do it this way by adding a custom variable to the data repeater -->
         <asp:ImageButton ImageUrl="<%# Container.DataItem("OakTreeThumbURL") %>" AlternateText="" runat="server" />
      </ItemTemplate>
   </asp:Repeater>
</ContentTemplate>

I would like to manipulate the "OakTreeName" variable before it gets placed into the item template. Basically I need to manipulate the "OakTreeName" variable and then input it as the ImageURL for the imagebutton within the item template. How do I do this?

Am I approaching this wrong? Is there a way to manipulate the item template from code-behind before it gets displayed for each round of variables in the data repeater?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about repeater