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.