我编写了以下代码,用于从sharepoint列表中检索数据并将其显示在datagridview上,但它只显示了sharepoint列表的最后一行。我不明白问题是什么。另外,我需要选择标题名称,并在datagridview中显示它的相关数据。
if (items2["Title"].ToString() == items["Name"].ToString())
{
if (aaitems1.Count > 0)
{
if (items2["Title"] != null)
{
FieldUserValue ICDe_No = items2["ICDe_x0020_No"] as FieldUserValue;
FieldUserValue smt1 = items2["SMT"] as FieldUserValue;
FieldUserValue object_code = items2["Object_Code"] as FieldUserValue;
FieldUserValue interface_name = items2["Interface_x0020_Name"] as FieldUserValue;
FieldUserValue dre_name = items2["DRE_x0020_Name"] as FieldUserValue;
if (items2["ICDe_x0020_No"] != null)
{
dataGridView1.Rows[index].Cells["ICDe_No"].Value = items2["ICDe_x0020_No"].ToString();
//dataGridView1.Rows.Add(icdeno);
}
else
{
dataGridView1.Rows[index].Cells["ICDe_No"].Value = "";
}
if (items2["SMT"] != null)
{
dataGridView1.Rows[index].Cells["SMT"].Value = items2["SMT"].ToString();
// dataGridView1.Rows.Add(smt);
}
else
{
dataGridView1.Rows[index].Cells["SMT"].Value = "";
}
if (items2["Object_Code"] != null)
{
dataGridView1.Rows[index].Cells["Object_Code"].Value = items2["Object_Code"].ToString();
//dataGridView1.Rows.Add(objectcode);
}
else
{
dataGridView1.Rows[index].Cells["Object_Code"].Value = "";
}
if (items2["Interface_x0020_Name"] != null)
{
dataGridView1.Rows[index].Cells["Interface_Name"].Value = items2["Interface_x0020_Name"].ToString();
//dataGridView1.Rows.Add(interfacename);
}
else
{
dataGridView1.Rows[index].Cells["Interface_Name"].Value = "";
}
if (items2["DRE_x0020_Name"] != null)
{
dataGridView1.Rows[index].Cells["DRE_Name"].Value = items2["DRE_x0020_Name"].ToString();
// dataGridView1.Rows.Add(drename);
}
else
{
dataGridView1.Rows[index].Cells["DRE_Name"].Value = "";
}
//dataGridView1.DataSource = items2["Title"].ToString();
// dataGridView1.Show();
}
}
else
{
// label2.Text = "Your components cannot be displayed";
}
}
答案 0 :(得分:0)
即使我们没有完整的代码,我也会说你没有增加索引变量。
问候。