私のWebアプリケーションでは、動的なデータテーブルを使用しています。
選択したパスを渡すにはどうすればよいですか 従業員ID 別のページに 削除 クリックされますか?
使っています 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() });
}
これまでのところ、私のURLは見えます DeleteEmployee.aspx?Employee_Id
、これで選択した従業員IDを取得するにはどうすればよいですか?
回答:
回答№1は1次のコードを使用して従業員も追加してみてください:
html.Append("<a href="DeleteEmployee.aspx?Employee_Id=" + row["EmployeeID"] + "">");
または、C#6 +を使用している場合は、文字列補間を使用します。
html.Append($"<a href="DeleteEmployee.aspx?Employee_Id={row["EmployeeID"]}">");