2013-06-20 50 views
0

我有一个datagridview,我用SQL绑定了这个网格,我在数据网格中添加了五行,与sql中的相同,使用autogeneratecolumn = false.使用autogeneratecolumn = false绑定数据网格

我的代码是

string qry1 = "select modal,Spec,color,Types,reqQty from godownRequsition where gr='" + txtGr.Text + "'"; 

dataGridView1.DataSource = DAL.GetdataTable(qry1); 

的问题是,当我运行程序,DataGrid的行无法显示数据。如果我完成datagrid中的所有列并且自动生成列为true,则显示数据..

现在我想将datagrid与自己生成的列绑定,而不是自动生成。

+2

请分享您的代码 – Pawan

+0

我想你必须设置数据源后使用的DataBind? –

+0

请发布您的Aspx代码。 –

回答

1

您需要通过你的自我这样创建列:

DataGridViewColumn column = new DataGridViewTextBoxColumn(); 
     column.HeaderText = "Lama"; 
     int indexCol = grid.Columns.Add(column); 
+0

int indexCol = grid.Columns.Add(column); // whats doing code line –

+0

that gives the index to put content into it(you can put it into a list or something to retrieve it after)。 – 3wic

+0

DataGridViewColumn column = new DataGridViewTextBoxColumn(); column.HeaderText =“Lama”; int indexCol = grid.Columns.Add(column); //此代码添加两列而不是一个 –