2016-05-11 156 views
0

我的数据网格没有显示在我的网页中,因为在没有表格显示。 我确实遵循这个堆栈question,并修改了它的一些代码来适合我的,但它根本没有显示。Datagrid没有显示

这里是我的类由按钮触发的代码。

private void LoadDataGrid() 
    { 
     con.Open(); 

     cmd = new SqlCommand(@"SELECT quotationID,quo_product 
          FROM JobQuotations 
          WHERE quo_custname = @custname", con); 
     cmd.Parameters.AddWithValue("@custname",lblLoginName.Text); 
     da = new SqlDataAdapter(cmd); 
     dt = new DataTable(); 
     GridView1.DataSource = dt; 
     GridView1.DataBind(); 
     con.Close(); 
    } 

,我已经插入它的Page_Load

protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 
      LoadDataGrid(); 
     } 
    } 

这里里面的标记:

<asp:GridView ID="GridView1" runat="server"></asp:GridView> 
+0

显示网格标记。浏览你的代码,是否有任何错误? – DGibbs

+0

@DGibbs等我要编辑它。 –

+0

此类似:http://stackoverflow.com/questions/35796348/datatable-dt-ds-tablesput-why-dt-is-null –

回答

0

你缺少da.Fill(dt);

dt = new DataTable(); 
da.Fill(dt); 
GridView1.DataSource = dt; 
+0

让我尝试添加it.wait为秒。 –