我想填补网格的第一个&第二列包含query1,第三列包含query2,第四列包含query3。
代码在网格的RowDataBound
事件中运行,但它不起作用:
protected void gvInner_RowDataBound(object sender, GridViewRowEventArgs e)
{
gvInner.Visible = true;
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label iso = (Label)gvInner.FindControl("lbl_iso");
Label description = (Label)gvInner.FindControl("lbl_desp");
string str1 = @"SELECT M_MR_ISO_Heads.iso as iso, M_MR_ISO_Heads.description as description
FROM
T_MR_Action_point_Pre_MRM_C INNER JOIN M_MR_ISO_Heads
ON T_MR_Action_point_Pre_MRM_C.iso_heads = M_MR_ISO_Heads.description";
DataTable dt = new DataTable();
dt = SQL_DB.ExecuteDataTable(str1);
if (dt.Rows.Count > 0)
{
iso.Text = dt.Rows[0]["iso"].ToString();
description.Text = dt.Rows[0]["description"].ToString();
}
Label mrmpoints = (Label)gvInner.FindControl("lbl_mrmpoints");
string str2 = @"SELECT T_MR_Action_point_Pre_MRM_C.mrm_no as mrmpoints
FROM
T_MR_Action_point_Pre_MRM_C INNER JOIN M_MR_ISO_Heads
ON T_MR_Action_point_Pre_MRM_C.iso_heads = M_MR_ISO_Heads.description
AND T_MR_Action_point_Pre_MRM_C.iso_heads = M_MR_ISO_Heads.description";
DataTable dt1 = new DataTable();
dt1 = SQL_DB.ExecuteDataTable(str2);
if (dt1.Rows.Count > 0)
{
mrmpoints.Text = dt1.Rows[0]["mrmpoints"].ToString();
}
Label totalpoints = (Label)gvInner.FindControl("lbl_tpoints");
string str3 = @"SELECT Count(T_MR_Action_point_Pre_MRM_C.mrm_no) as totalpoints
FROM
T_MR_Action_point_Pre_MRM_C INNER JOIN M_MR_ISO_Heads
ON T_MR_Action_point_Pre_MRM_C.iso_heads = M_MR_ISO_Heads.description
AND T_MR_Action_point_Pre_MRM_C.iso_heads = M_MR_ISO_Heads.description";
DataTable dt2 = new DataTable();
dt2 = SQL_DB.ExecuteDataTable(str3);
if (dt2.Rows.Count > 0)
{
totalpoints.Text = dt2.Rows[0]["totalpoints"].ToString();
}
}
}
答案 0 :(得分:0)
更改这些行。
Label iso = (Label)gvInner.FindControl("lbl_iso");
Label description = (Label)gvInner.FindControl("lbl_desp");
使用
Label iso = (Label)e.Row.FindControl("lbl_iso");
Label description = (Label)e.Row.FindControl("lbl_desp");