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>
顯示網格標記。瀏覽你的代碼,是否有任何錯誤? – DGibbs
@DGibbs等我要編輯它。 –
此類似:http://stackoverflow.com/questions/35796348/datatable-dt-ds-tablesput-why-dt-is-null –