![](/img/trans.png)
[英]Why can't I successfully bind a DataGridviewColumnCollection to a ComboBox.DataSource and specify a Display/ValueMember?
[英]Why can't I bind a formview to this datasource?
我在這里有此代碼:
SqlCommand CodeStatus = new SqlCommand(SQL, DB);
DB.Open();
Reader = CodeStatus.ExecuteReader();
FormView1.DataSource = Reader;
FormView1.DataBind();
DB.Close();
它與gridview一起使用,然后顯示數據,但是在此formview中,它不顯示數據。 為什么不? 默認模式為只讀,僅應顯示數據。
您的FormView是否具有ItemTemplate?
MSDN似乎暗示,盡管可能,但您需要一個。
我知道這並不能直接回答您的問題,但是您是否嘗試過使用DataTable?
using(SqlDataAdapter adapter = new SqlDataAdapter(sql,connection))
{
DataTable table = new DataTable();
adapter.Fill(table);
FormView1.DataSource = table;
FormView1.DataBind();
}
MSDN將FormvView定義為“ FormView使用用戶定義的模板顯示來自數據源的單個記錄的值”。
因此,您需要看一些事情-
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.