I’ve an item template inside a grid which has a <asp:LinkButton/> inside it. I assign the text for the link button as
<%# Convert.ToString(Eval("Tags"))%>
Tags can have a string with multiple tags in it delimited by space. For eg. “sports”, “sports cricket”, “sports cricket sachin” are the examples of some possible tags.
I want to create a button for each tag inside the string. How can i create the controls (server control – linkbutton) dynamically during runtime inside the grid item template?
Thank you
I assuming the grid you are referring to is a data grid?
This tutorial has a great example. To summarise:
Add a Template column to your grid view in place of the link button column:
Note that tagSplitChars should be defined in your code behind as:
Clearly you can add an “onclick” handler to you link button as you need.
I have tested this with this code behind and it works perfectly:
UPDATE
If you are just trying to add a list of buttons, and have no other columns to display in your grid, you can simplify the solution significantly:
Then in the code behind
Clearly you will have to access the data in your datatable manually to extract the string, haven’t done this in a while but from memory it is quite simple.