0

So I am currently trying to add a button for each row that I am displaying in a webpage from a database using html string appendings. Here is the code that I have written so far.

//Building the Data rows.
        foreach (DataRow row in dt.Rows)
        {
            html.Append("<tr>");

            html.Append("<td>");
            html.Append(row["user_name"]);
            html.Append("</td>");

            html.Append("<td>");
            html.Append(row["first_name"]);
            html.Append("</td>");

            html.Append("<td>");
            html.Append(row["last_name"]);
            html.Append("</td>");

            html.Append("<td>");
            html.Append(row["email"]);
            html.Append("</td>");

            html.Append("<td>");
            html.Append(row["grade"]);
            html.Append("</td>");

            html.Append("<td>");
            html.Append("< asp:Button ID = " + row["user_name"] + "Remove" + " runat = " + "server" + " Text = " + "Remove" + " />");
            html.Append("</td>");

            html.Append("</tr>");
        }

As you can see at the last appending in the foreach loop, I am trying the append the text needed for creating a button with its own unique ID. However, when I load the page, it just types in the literal string in the spot where the button is supposed to be. Should I be adding buttons in a different way entirely? Because looking into the future, once I have these buttons set up I am not entirely sure how I will access each event individually (since the buttons are added dynamically but I do not know how to add C# code dynamically for each button created).

Sohee
  • 23
  • 5

0 Answers0