0
我有一個GridView綁定到ObjectDataSoure。GridView(綁定到ObjectDataSource)在字段對話框中的選定字段區域中不顯示字段
ObjectDataSource使用一個業務對象,該對象調用返回DataTable和查詢結果的DAL方法。
應用工程在運行時,但在設計時有一個問題: 當我使用GridView的任務嚮導 - >編輯列:沒有字段出現在選定字段的文本區域(這樣我就可以」使用嚮導來編輯列)。
DAL方法:
public override DataTable GetAllWorkers()
{
using (SqlConnection con = new SqlConnection(this.ConnectionString)) {
SqlCommand cmd = new SqlCommand("t_Workers_GetAllWorkers", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
return GetTable(cmd);
}
}
private DataTable GetTable(SqlCommand cmd)
{
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = cmd;
DataTable dt = new DataTable();
adp.Fill(dt);
return dt;
}
BLL方法:
public static DataTable GetAllWorkers()
{
return DataProvider.Instance().GetAllWorkers();
}
ASPX網頁:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetAllWorkers" TypeName="BLL.BizImpl"></asp:ObjectDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1"
EnableModelValidation="True" Height="156px" Width="270px">
</asp:GridView>
可有人請解釋什麼是該問題的原因是什麼?
Thanks
謝謝您的回答。當我嘗試使用SqlDataSource時,所有列都出現在設計時的選定字段文本區域中。那麼當我使用ObjectDataSoure的時候不喜歡乳清?在ASPX文件中手動定義列是我唯一的選擇嗎? – ProgNet
爲什麼不使用SqlDataSource呢? – chead23
說實話,我不太清楚爲什麼它能與一個而不是另一個協同工作。我會嘗試手動定義列。如果你能夠在SqlDataSource中完成而不需要定義列,那麼它在哪裏存儲格式化信息,你注意到它是否在aspx中? – chead23