I have a SQL table that I'm using to populate a table, and I want to add 'Delete' and 'Edit' Buttons to the row.
I have an input textbox corresponding to a column in my sql table, "PartNo". I currently have two functions: BuildTable and GetData, both a called when a button is pushed. GetData() makes the connection with the sql database and queries for data with the user specified PartNo, and BuildTable uses a StringBuilder class to create an html table and populate it with the sql data. I want each row to have a delete and edit button for which can delete and edit that specific row.
protected void BuildTable(Datatable dt){
//Building an HTML string;
StringBuilder html = new StringBuilder();
html.Append("<h3><b>Parts Location Details</b></h3>");
//table start
html.Append("<table align='center' bgcolor='#dbdbdb'>");
//Building the Header row.
html.Append("<tr >");
foreach (DataColumn column in dt.Columns)
{
html.Append("<th style='color: white' bgcolor='darkblue'>");
html.Append(column.ColumnName);
html.Append("</th>");
}
html.Append("<th style ='color:white' bgcolor ='blue'>Edit</th>");
html.Append("<th style ='color:white' bgcolor ='blue'>Delete</th>");
html.Append("<th style ='color:white' bgcolor ='blue'>Print</th>");
html.Append("<tr>");
//building the data row
foreach (DataRow row in dt.Rows)
{
countRows++;
html.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
html.Append("<td>");
html.Append(row[column.ColumnName]);
html.Append("</td>");
}
html.Append("<td><input type='button' value='Edit'/></td>");
html.Append("<td><input type='button' value='Delete' runat='server' onclick='btndelete_Click'/></td>");
//html.Append("<td><asp:button ID='delete' runat='server' Text='Delete' OnClick='btndelete'/></td>");
html.Append("<td><input type='button' value='Print'/></td>");
html.Append("</tr>");
}
//table end
html.Append("</table>");
//append the HTML string to PlaceHolder with ID=spDetailsNew
spDetailsNew.Controls.Add(new Literal { Text = html.ToString() });
}
I have tried using a regular html input button and an asp:button object; the asp:button object doesn't show on the table, and the input button's 'onclick' function isn't called when it's clicked. I haven't coded the Delete onclick function yet; it's just supposed to give an alert that the Delete button has been pushed, and it's not doing that.