如何在datagridview中显示结果?

时间:2016-06-17 15:50:20

标签: c#

我有一个名为PSelectAllQuestion的存储过程可以返回问题。 我使用linq分配下面的代码。

var allSelectedQuestion = glnq.PSelectAllQuestion(Convert.ToInt32(comboBox1.SelectedValue));

我使用以下代码从allSelectedQuestion中随机选择行:

var randomSelectedQuestion = allSelectedQuestion.Where(c => c.QuestionID == 4).Select(c=>c);

并将其分配给dataGridView1

dataGridView1.DataSource = randomSelectedQuestion; 

当我运行代码dataGridView1时什么也没有显示。问题是什么?

1 个答案:

答案 0 :(得分:0)

您需要通过执行以下操作将数据绑定到数据网格中:

dataGridView1.DataBind();

分配数据源之后。