A binding technique of Asp.net 2.0

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.