У меня динамически создается bootstrap
html table
из database
. Это шаблон дизайна таблицы, который я использую: https://bootsnipp.com/snippets/8G2Q
это кнопка, которую я пытаюсь добавить в столбцы "del": https://getbootstrap.com/docs/4.0/components/buttons/ (Опасно)
void main()
{
SqlCommand command = new SqlCommand();
SqlConnection conn = Connect.main();
command = new SqlCommand("Select * from dbo.Suppliers", conn);
SqlDataAdapter da = new SqlDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
dt.Columns.Remove("country");
dt.Columns.Remove("state");
dt.Columns.Remove("street_name");
dt.Columns.Remove("street_number");
dt.Columns.Remove("rep_first_name");
dt.Columns.Remove("rep_last_name");
dt.Columns.Remove("rep_contact_number");
dt.Columns.Remove("rep_email");
String html = ConvertDataTableToHTML(dt);
String core;// = ConvertDataTableToHTML(dt);
conn.Close();
String formated = String.Format(@"
<div class='container'>
<div class='panel panel-primary filterable'>
<div class='panel-heading'>
<h3 class='panel-title'>Suppliers</h3>
</div>
<table class='table' >
<thead>
<tr class='filters'>
<th><input type = 'text' class='form-control' placeholder='#'></th>
<th><input type = 'text' class='form-control' placeholder='Name'></th>
<th><input type = 'text' class='form-control' placeholder='Phone # 1'></th>
<th><input type = 'text' class='form-control' placeholder='Phone # 2'></th>
<th><input type = 'text' class='form-control' placeholder='Email 1'></th>
<th><input type = 'text' class='form-control' placeholder='Email 2'></th>
<th><input type = 'text' class='form-control' placeholder='Website'></th>
<th><input type = 'text' class='form-control' placeholder='Active'></th>
<th><input type = 'text' class='form-control' placeholder='Del'></th>
</tr>
</thead>
<tbody>
{0}
</tbody>
</table>
</div>
</div>
</div>
", html);
myDiv.InnerHtml = formated;
}
public string ConvertDataTableToHTML(DataTable dt)
{
string html ="";// = "<table>";
/*
//add header row
html = "<tr>";
for (int i = 0; i < dt.Columns.Count; i++)
html += "<td>" + dt.Columns[i].ColumnName + "</td>";
html += "</tr>";*/
//add rows
for (int i = 0; i < dt.Rows.Count; i++)
{
html += "<tr>";
for (int j = 0; j < dt.Columns.Count; j++)
html += "<td>" + dt.Rows[i][j].ToString() + "</td>";
///////////////////////////////////////// this is testing code for the button creation
// html += "<td>" + "<input type='submit' name='name' value='Save' runat='server' />" + "<td>";
HtmlButton btn = new HtmlButton();
btn.ID = "myID";
btn.Attributes["class"] = "mdl-button mdl-js-button mdl-button--fab mdl-button--colored";
btn.InnerHtml = "<i class=\"material-icons\">add</i>";
html += "<td>" + btn + "<td>";
/////////////////////////////////////////
///
html += "</tr>";
}
// html += "</table>";
return html;
}
Я не могу понять, как добавить этот конкретный тип кнопки в таблицу, которую я делаю. Может ли кто-нибудь указать мне правильное направление? Я экспериментировал с различными типами кнопок, хотя мне действительно нужно, чтобы они выглядели так, как показано на этой ссылке, приведенной выше.