Data List populated from stored procedure

微笑、不失礼 提交于 2019-12-13 20:14:31

问题


Here's a concrete example in 5 short steps:

1) I have built a Data List in the Design view of an "ASCX" file.

2) In the Item Template area of the Data List, I created a 1x3 table, and in each cell I specified as below using Eval(“columnx”) a column (fid) returned through a Stored Procedure.

<asp:Label ID="Label1" runat="server" Text='<%# Eval("fid") %>'>

In the same manner, I specified other two fields returned by the same stored procedure.

3) I went to the .ASCX.CS (code behind file) and specified the data source as being the stored procedure; and I did the data binding:

DataList1.DataSource = FilmsAccess.GetFilms(); DataList1.DataBind();

PS: FilmsAccess is a class inside App_Code that contains the GetFilms() method where the GetFilms stored procedure is passed and executed. The result of the SP is a datatable.

4) I went to my master page and copied the data list there, inside a contentplaceholder.

5) I created a page called Catalog.aspx that inherits from the master. I defaulted its ContentPlaceHolder to what the master shows from design view. As a result, Catalog opens, but I don’t see the datalist - AT ALL. What am I doing wrong?? Thank you for reading and following up!


回答1:


Not sure if it helps, but here is a line from one of my old web apps where the result of a bound dataset is being given to an asp label:

<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Network_Name") %>'/>



回答2:


I have the answer: Step 4) above was wrong. Instead of copying the data list contained within the ascx file, one needs to drag and drop the entire ascx file into where it is needed (in this case, into Catalog.aspx)! Have a nice day everyone!



来源:https://stackoverflow.com/questions/10614687/data-list-populated-from-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!