Previously, the data record information displayed on the page was in the gridview control. Although this space is very useful, there are some shortcomings in the United States. For example, you can add a value before each data record, it is not natural to use the gridview control.
Go back to the backgroundCodeIn combination with the HTML language, you can also achieve a display effect similar to the gridview control, and better. Let's not talk about it. The Code goes first!
The method code is as follows:
Protected string STR;
Protected void page_load (Object sender, eventargs E)
{
Databind ();
}
Private void databind ()
{
String SQL, picstr, left_str, cen_str, hig_str;
Int N;
N = 8;
Left_str = "8px ";
Cen_str = "2px ";
Hig_str = "20px ";
SQL = "select Top 8. kecbh,. kecmc, convert (char (10),. tianjrq, 120) as tianjrq, B. fuzrbh, B. yonghbh, D. xingm ";
SQL + = "from t_jingpka, t_kecry B, t_jiaos D ";
SQL + = "where a. kecdjbh = 3 and A. kecbh = B. kecbh and B. yonghbh = D. yonghbh ";
SQL + = "and A. keclxbh = 1 and B. leixbh = 2 order by A. tianjrq DESC ";
STR = "<Table width = 100% border = 0 cellpadding = 0 cellspacing = 0> ";
Dataset DS = new dataset ();
DS = Get. datasets (SQL );
String kcid, kcmc, fzr, RQ;
For (INT I = 0; I <Ds. Tables [0]. Rows. Count; I ++)
{
Kcid = Ds. Tables [0]. Rows [I] ["kecbh"]. tostring ();
Kcmc = Ds. Tables [0]. Rows [I] ["kecmc"]. tostring ();
Fzr = Ds. Tables [0]. Rows [I] ["xingm"]. tostring ();
RQ = Ds. Tables [0]. Rows [I] ["tianjrq"]. tostring ();
STR + = "<tr> <TD width = 100% style = 'padding-left :";
STR + = left_str + "; letter-Spacing:" + cen_str + "; line-Height:" + hig_str;
STR + = "; Background-position: left center; Background-repeat: No-Repeat; Background-image: URL (" + picstr + "); '> ";
STR + = "<a href = http: // 211.69.16.170/jpkc_mb.aspx? Kecbh = "+ kcid +" target = _ blank> ";
STR + = "<font color = '#000000'> ";
STR + = "& nbsp ;";
STR + = kcmc;
STR + = "</font> ";
STR + = "</a> ";
If (convert. toint32 (system. datetime. Now-convert. todatetime (RQ). Days) <5)
STR + = "[<font color = Red> New </font>]";
STR + = "</TD> ";
STR + = "</tr> ";
}
STR + = "<tr> <TD width = 100% align = right> ";
STR + = "<a href ='' target = _ blank> More >></A> ";
STR + = "</TD> </tr> ";
STR + = "</table> ";
}
The above mainly uses the character variable STR to set the display style, and then generate the form of a table to display data information.
Return the output string parameter str in the. aspx. CS file.
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "maininfor_gjjpkc.aspx.cs" inherits = "maininfor_gjjpkpk" %>
Document. Write ("<% = STR %> ");
If you have any better methods and suggestions, please give us some advice!