-1

I want to add a span with code behind to a itemTemple (inside a gridview)

<itemTemplate>
    // Here i want a span build up with code behind
    <asp:HyperLink ID="hyperlinkID" runat="server">#</asp:HyperLink>
</itemTemplate>

Is this even posible or do i need to declare a placeholder in the aspx.

  • You can do it without having anything in the markup but it would be dificult to control the positioning and I think you are just making the job harder. I would add a `` to the markup and set the Text property. If you do not set Text to anything then nothing will render to the browser. – Ben Robinson Nov 25 '14 at 13:38

1 Answers1

2

A span which you want to access on serverside is a Label that is rendered as span later.

<ItemTemplate>
    <asp:Label ID="LblId" runat="server" Text='<%# Bind("TextColumn") %>'></asp:Label>
</ItemTemplate>

If you want to hide it under certain conditions i would use the RowDataBound-event. Visible=false on server-side means that it's not rendered at all on client-side.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • Thank you for the feedback. is it possible to add the label dynamicly in the rowdatabound method, instead of in the aspx? – kishen Biekhram Nov 25 '14 at 14:18
  • @kishenBiekhram: you can switch visibility in `RowDataBound`. I'd declare it anyway. `Visible=false` means that it's not rendered at all on client-side. – Tim Schmelter Nov 25 '14 at 14:21