2016-05-11 77 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爲秒。 –