如何使用Url将选择的原始数据传递到另一个页面?

时间:2017-08-29 05:23:16

标签: c# asp.net

在我的网络应用程序中,我使用的是动态数据表enter image description here

如果点击删除,如何将所选的员工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() });
}

到目前为止,我的网址看起来DeleteEmployee.aspx?Employee_Id,我怎样才能获得所选择的员工ID???

1 个答案:

答案 0 :(得分:1)

您可以尝试使用此代码附加员工:

html.Append("<a href='DeleteEmployee.aspx?Employee_Id=" + row["EmployeeID"] + "'>");

或者如果您使用的是C#6 +,请使用字符串插值。

html.Append($"<a href='DeleteEmployee.aspx?Employee_Id={row["EmployeeID"]}'>");