Problem summary:
I'm making a request to a database where I fetch created reports based on a user.
These will be listed in a table with a download button with each report where the user can download the report where that button is.
I need to know what report will be used when the button is clicked. This is where the problem is.
My solution so far won't render the asp:button
- element from the StringBuilder
. But if I place it in the HTML-file with just a basic input it will show.
My Code behind look like this:
SqlDataReader sqlReader = DataFromADatabaseRequest
StringBuilder table = new StringBuilder();
table.Append("<table border='1'>");
table.Append(
"<tr>" +
"<th>ID</th>" +
"<th>Name</th>" +
"<th>Prefix</th>" +
"</tr>");
if (sqlReader.HasRows)
{
while (sqlReader.Read())
{
string uniqueIdentifierToFindWhatButtonIsClicked = sqlReader["Prefix"].ToString();
table.Append("<tr>");
table.Append("<td>" + sqlReader["Id"] + " </td>");
table.Append("<td>" + sqlReader["Name"] + " </td>");
table.Append("<td> <asp:Button id="btn_" + uniqueIdentifierToFindWhatButtonIsClicked + "' class='btnDownloadFile' CommandName=" + uniqueIdentifierToFindWhatButtonIsClicked + "/> </td>");
table.Append("</tr>");
}
}
table.Append("</table>");
I then send this tablestring
into an asp:placeholder
where this table is shown.
Everything works fine. But the button won't show.
If I use like a normal <input type="button" />
this works but then I can't hook a code-behind event allowing me to pass a parameter.
Thankful for all help.