将数据表值绑定到数据网格的问题 [英] problem on binding datatable value to datagrid
本文介绍了将数据表值绑定到数据网格的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,
以下代码用于将数据表绑定到datagridview.
Hi friends,
The following code for binding datatable to datagridview.
DataTable dt = new DataTable();
DataColumn dc;
dc = new DataColumn("AdmissionNumber");
dt.Columns.Add(dc);
dc = new DataColumn("StudentName");
dt.Columns.Add(dc);
dc = new DataColumn("Class");
dt.Columns.Add(dc);
dc = new DataColumn("Section");
dt.Columns.Add(dc);
string studentname=comboBox4.Text;
int classname =int.Parse( comboBox2.SelectedValue.ToString());
DataRow dr =dt.NewRow();
dr["AdmissionNumber"] =Convert.ToString( ibl4.bindadminid(studentname,classname));
dr["StudentName"] = comboBox4.Text;
dr["Class"] = comboBox2.Text;
dr["Section"] = comboBox3.Text;
dataGridView2.DataSource = dt;
运行时,应用程序gridview在gridview单元格中不显示该值.有什么问题吗?注意.
中可用的值
when run the application gridview doesnt show the value in the gridview cell. What is the problem?.note. values available in
Convert.ToString( ibl4.bindadminid(studentname,classname));
和
and
comboBox4.Text;
comboBox2.Text;
comboBox3.Text;
预先谢谢您
Advance Thank you
推荐答案
在设置数据源之前尝试此操作
try this before set datasource
dt.Rows.Add(dr);
dataGridView2.DataSource = dt;
这篇关于将数据表值绑定到数据网格的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文