0

我正在使用网格视图,如果我将鼠标指向每一行,我需要在弹出窗口中的表格/网格中显示特定细节。我已经尝试了以下相同的代码,它正在工作,但在弹出窗口中只显示一行:

 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        PopupControlExtender pce = e.Row.FindControl("PopupControlExtender1") as PopupControlExtender;

        string behaviorID = "pce_" + e.Row.RowIndex;
        pce.BehaviorID = behaviorID;

        Image img = (Image)e.Row.FindControl("Image1");

        string OnMouseOverScript = string.Format("$find('{0}').showPopup();", behaviorID);
        string OnMouseOutScript = string.Format("$find('{0}').hidePopup();", behaviorID);

        img.Attributes.Add("onmouseover", OnMouseOverScript);
        img.Attributes.Add("onmouseout", OnMouseOutScript);
    }
}


 [System.Web.Services.WebMethodAttribute(),
    System.Web.Script.Services.ScriptMethodAttribute()]
    public static string GetDynamicContent(string contextKey)
    {
        string constr = ConfigurationSettings.AppSettings["ConnectionInfo"];
        SqlConnection con = new SqlConnection(constr);
        con.Open();
        string query = "SELECT * FROM Table1 WHERE field1 = '" + contextKey + "' ";

        SqlDataAdapter da = new SqlDataAdapter(query, con);
        DataTable table = new DataTable();

        da.Fill(table);

        StringBuilder b = new StringBuilder();
    b.Append("<table border='1' style='background-color:#f3f3f3; ");
    b.Append("width:350px; font-size:10pt; font-family:Verdana;' cellspacing='0' cellpadding='3'>");

    b.Append("<tr style = 'background-image: url(Images/HeaderGlassBlack.jpg); background-repeat:repeat; color:#FFC700; '><td style='width:50px;'><b>Employee</b></td>");
    b.Append("<td style='width:80px;'><b>KPI Name</b></td>");
    b.Append("<td style='width:80px;'><b>Business</b></td>");
    b.Append("<td style='width:80px;'><b>Description</b></td>");

    b.Append("<td style='width:50px;'><b>Plan Live</b></td>");
    b.Append("<td style='width:80px;'><b>Actual Live</b></td>");
    b.Append("<td style='width:80px;'><b>Plan Q1</b></td>");
    b.Append("<td style='width:80px;'><b>Actual Q1</b></td></tr>");

    b.Append("<tr>");
    b.Append("<td>" + table.Rows[0]["Emp_Name"].ToString() + "</td>");
    b.Append("<td>" + table.Rows[0]["kpi_name"].ToString() + "</td>");
    b.Append("<td>" + table.Rows[0]["Bus_Name"].ToString() + "</td>");
    b.Append("<td>" + table.Rows[0]["Description"].ToString() + "</td>");
    b.Append("<td>" + table.Rows[0]["PLAN_LIVE"].ToString() + "</td>");
    b.Append("<td>" + table.Rows[0]["ACTUAL_LIVE"].ToString() + "</td>");
    b.Append("<td>" + table.Rows[0]["PLAN_Q1"].ToString() + "</td>");
    b.Append("<td>" + table.Rows[0]["ACTUAL_Q1"].ToString() + "</td>");


    b.Append("</tr>");

    b.Append("</table>");

    return b.ToString();
}

我知道我需要遍历数据集以填充动态表中的所有值,但我不知道如何实现这一点。有人可以帮忙吗?

4

2 回答 2

1

您可以尝试使用此代码

b.Append("<table>");
//Here you add attributes of table
.... 
foreach(var row in table.Rows)
{

    b.Append("<tr>");
    b.Append("<td>");
    b.Append(row["Emp_Name"].ToString());
    b.Append("</td>"); 
    //here you add your differents cells
    .......
    b.Append("</tr>");
}
//Close your table
b.Append("</table>");

.... 
于 2012-10-15T13:01:51.440 回答
0

为什么不使用AjaxToolkit的悬停菜单?

于 2012-10-15T13:18:44.657 回答