簡體   English   中英

如何使用業務對象和存儲過程填充窗體視圖? (DataSource對象/ DataBound控件)

[英]How do I populate a Form View with business object and stored procedure? (DataSource objects/DataBound Controls)

我成功地使用了一個業務對象,一個存儲過程和結構來填充一個頁面,其中包含一個Text Box控件列表,可以顯示並允許編輯一些客戶詳細信息數據。 我單獨將每個Text Box控件分配給struct中的值。

然后,我成功使用SqlDataSource填充表單視圖以顯示相同的客戶詳細信息數據。

我現在想要使用總線對象,存儲過程和結構(或其他對象)在窗體視圖中顯示客戶詳細信息數據。

以下是我如何調用業務對象來獲取數據並將其返回到“客戶詳細信息”頁面的“加載”事件中的結構中:

 CustomerDetailsStruct cd = CustomerDetailsAccess.GetCustomerDetails(customerId);

如何告訴表單視圖使用結構? 或者,我是否需要將數據檢索到其他對象?

這是我最初使用SqlDataSource時顯示客戶詳細信息數據的頁面中的代碼:

    <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" CellPadding="4" DataKeyNames="CustomerID" ForeColor="#333333">

我看到有一個可用的DataSource屬性。 此MSDN頁面上的示例使用DataSet。 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.formview.aspx我還閱讀了MSDN上的ObjectDataSource。

如果我需要提供更多詳細信息或更多代碼,請與我們聯系。

我還想問一個更廣泛的問題:有人可以推薦一本可以解釋DataSource對象和DataBound控件以及如何配對的好書或網站嗎? 我目前正在閱讀一本書,里面有一些關於如何做某些事情的好例子。 但是,有沒有一個很好的參考指南數據綁定?


這是我的表格視圖。

TheKingDave:我沒有DataSource或DataSourceID屬性,因為我不知道如何在Page_Load事件中使用struct或備用對象作為我的數據源,這是我的主要問題。 我在Page_Load事件中獲取結構。 我想我需要以某種方式使它成為數據源:

                // Get the Customer Details data with the business object.
        CustomerDetailsStruct cd = CustomerDetailsAccess.GetCustomerDetails(customerId);

這是EditItemTemplate的開始。 我從使用SqlDataSource的表單視圖中的代碼復制/粘貼它,因此我不必重新創建表。 它只是一個包含EditItemTemplate中的文本框控件和ItemItemplate中的標簽的表。

    <asp:FormView ID="FormView1" runat="server"  CellPadding="4"  ForeColor="#333333">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditItemTemplate>

    <table cellpadding="5" class="UserDetailsTable">       
   <tr>
        <td class="UserDetailsTitleCell">Address1:</td>
        <td><asp:TextBox ID="Address1TextBox" runat="server" Text='<%# Bind("Address1") %>'>
        </asp:TextBox></td>
   </tr> 

這是項目模板的開頭:

        <ItemTemplate>
    <table cellpadding="5" class="UserDetailsTable">
<tr>
    <th colspan="2">Customer Details:</th> 
</tr> 
    <tr>
        <td class="UserDetailsTitleCell">Address1:</td>
    <td class="UserDetailsTitleCell"><asp:Label ID="Address1Label" runat="server" Text='<%# Bind("Address1") %>'></asp:Label></td> 
    </tr>

需要更多/別的什么?

嘗試這個:

CustomerDetailsStruct cd = CustomerDetailsAccess.GetCustomerDetails(customerId);

//FormView DataSource has to be IListSource, IEnumerable, or IDataSource
List<CustomerDetailsStruct> list = new List<CustomerDetailsStruct>();
list.Add(cd);
FormView.DataSource = list;

//Choose the proper mode (templates have to be defined) 
FormView.ChangeMode(FormViewMode.ReadOnly);
FormView.DataBind();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM