An order issue in the Asp.net Control

Source: Internet
Author: User
I haven't written anything for a while. I will try again and stick to it.
When writing a website a few days ago, you need to create a custom control. The principle is very simple, that is, reading from the database and displaying it in its own format.
First approach:
Generate dataset in page_load event
Code As follows: Private   Void Page_load ( Object Sender, system. eventargs E)
{
Sqlconnection myconnection =   New Sqlconnection (configurationsettings. receivettings [ " Sqlconn " ]);
String Commandtext =   " Select top 10 vouch. *, Book. bookid, Book. bookname, Book. Price from vouch join book on vouch. bookid = book. bookid where vouch. type = "   + Type. tostring () +   " Order by vouch. vouchid DESC " ;
Sqldataadapter myadapter =   New Sqldataadapter (commandtext, myconnection );
Dataset DS =   New Dataset ();

Myadapter. Fill (DS );

}

Then display similar data on the page < TD Class = "H18" Width = "34%" >
< Span Class = "P14" >
< Strong >
< A Href = "Book/book. aspx? Bookid = <% = Ds. Tables [0]. Rows [0] [" Bookid "]. tostring () % > "Title =" <% = DS. Tables [ 0 ]. Rows [ 0 ] [ " Bookname " ]. Tostring () %> "> 《 <% = Cutstring (Ds. Tables [ 0 ]. Rows [ 0 ] [ " Bookname " ]. Tostring ()) %> "
< BR >
</ A >
</ Strong >
</ Span >
</ TD >

This cannot achieve the expected results.

If you use the properties of the control, the operation is successful.
This is the second approach:

Public   Int Type;


Public   Int Vouchtype
{
Get  
{
ReturnType;
}
Set
{
Type=Value;
}
}

Private   Void Page_load ( Object Sender, system. eventargs E)
{

}
Private Dataset getdataset ()
{
Sqlconnection myconnection =   New Sqlconnection (configurationsettings. receivettings [ " Sqlconn " ]);
String Commandtext =   " Select top 10 vouch. *, Book. bookid, Book. bookname, Book. Price from vouch join book on vouch. bookid = book. bookid where vouch. type = "   + Type. tostring () +   " Order by vouch. vouchid DESC " ;
Sqldataadapter myadapter =   New Sqldataadapter (commandtext, myconnection );
Dataset DS =   New Dataset ();

Myadapter. Fill (DS );
Return DS;
}

Public Dataset Source
{
Get
{
ReturnGetdataset ();
}
}

Make similar calls on the page < TD Class = "H18" Width = "34%" >
< Span Class = "P14" >
< Strong >
< A Href = "Book/book. aspx? Bookid = <% = This. Source. Tables [0]. Rows [0] [" Bookid "]. tostring () % > "Title =" <% = This. Source. Tables [ 0 ]. Rows [ 0 ] [ " Bookname " ]. Tostring () %> "> 《 <% = Cutstring (this. Source. Tables [ 0 ]. Rows [ 0 ] [ " Bookname " ]. Tostring ()) %> "
< BR >
</ A >
</ Strong >
</ Span >
</ TD >

This will succeed.

Through these two comparisons, this issue is very obvious. Although this detail may have been clear before, it is my own practical experience and I feel quite profound.

 

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.