I am still working on my graduation project, and now I have achieved the front-end
Code . I encountered another problem during data binding on the front-end page and finally solved it through my own efforts. I would like to share with you here. (I don't know if there were any similar
Article )
Preface:
The bll layer is basically a CRUD operation, which corresponds to the insert, select, update, and delete statements (Stored Procedures) in the database respectively. When reading data at the Dal layer (Read/select ), generally, a row of data or multiple rows of data are returned. When the BLL layer is returned, a logical object or a group of objects are returned, such as ilist <t>. In this way, you can use data binding controls such as objectdatasource and gridview to display data on the front-end page.
Problem:
We know that the objectdatasource control needs to specify the insert, select, update, and delete methods of the data object, but the problem is as follows, we usually need to display several attributes of another data object in the same gridview, so objectdatasource is powerless and we need to bind data by ourselves.
Solution:
After talking nonsense, I will explain the problem with my code.
The data object of objectdatasource is forum, and the select method is named "getforums". The Code is as follows:
< ASP: objectdatasource ID = " Objectperformance1 " Runat = " Server " Selectmethod = " Getforums " Typename = " RFID. BLL. Forum " > </ ASP: objectdatasource >
In this way, you can directly use the gridview to display the data, but I also need to display the last updated post of forum, which involves another data object "Post ", however, objectdatasource only returns the "Forum" object. You can only write the data binding code on the page.
First, add a function in the post code (Aspx. CS) on the front-end page to return the postinfo object. Protected Postinfo getlastpost ( Object Forumid)
{
IntForumid=Convert. toint32 (forumid );
Forum= NewForum ();
ReturnForum. getlastpost (forumid );
}
It is worth noting that the parameter type must be of the object type, because the returned value is of the object type when the foreground page is bound with eval ("forumid.
Next we can customize the binding on the front-end page, add an itemtemplate to the gridview, and insert the following code snippet: < ASP: literal ID = " Post " Runat = " Server " Text = ' <% # Getlastpost (eval ("forumid"). Title %> ' > </ ASP: literal >
TEXT = '<% # getlastpost (eval ("forumid ")). title (title is an attribute of the Data Object postinfo) is used to implement data binding using the User-Defined Function and eval (), thus solving the problem.