No meu aplicativo da web, estou usando uma tabela de dados dinâmica,
Como posso passar o selecionado ID do Empregado para outra página quando o Excluir é clicado ??
estou usando Função C #:
try
{
CommonClass CC = new CommonClass();
DataTable dt = CC.GetAllDetails("AllEmployee");
//Building an HTML string.
StringBuilder html = new StringBuilder();
//Table start.
html.Append("<table class="table table-striped table-hover" id="sample_2">");
//Building the Header row.
html.Append("<thead>");
html.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
html.Append("<th>");
html.Append(column.ColumnName);
html.Append("</th>");
}
html.Append("<th>");
html.Append("Delete");
html.Append("</th>");
html.Append("</tr>");
html.Append("</thead>");
html.Append("<tbody>");
//Building the Data rows.
foreach (DataRow row in dt.Rows)
{
html.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
html.Append("<td>");
html.Append(row[column.ColumnName]);
html.Append("</td>");
}
html.Append("<td>");
html.Append("<a href="DeleteEmployee.aspx?Employee_Id">");
html.Append("Delete");
html.Append("</a>");
html.Append("</td>");
}
html.Append("</tbody>");
//Table end.
html.Append("</table>");
//Append the HTML string to Placeholder.
PlaceHolder1.Controls.Add(new Literal { Text = html.ToString() });
}
até agora minha URL parece DeleteEmployee.aspx?Employee_Id
, como posso obter o ID do funcionário selecionado com isso .. ??
Respostas:
1 para resposta № 1você pode tentar anexar também o funcionário usando este código:
html.Append("<a href="DeleteEmployee.aspx?Employee_Id=" + row["EmployeeID"] + "">");
ou se você estiver usando C # 6 +, use interpolação de string.
html.Append($"<a href="DeleteEmployee.aspx?Employee_Id={row["EmployeeID"]}">");