I. Summary
// Code in the aspxl file: use... to automatically process the data in the bound data source cyclically.
<Asp: repeater id = "rptanswers" runat = "server">
<Itemtemplate>
<Asp: repeater id = "rptanswers" runat = "server">
<% # Databinder. eval (container. dataitem, "newstitle") %>
</Itemtemplate>
</ASP: repeater> code <! -- International. Domestic clinical progress: start -->
<Table cellspacing = "0" cellpadding = "0" width = "390" border = "0">
<Asp: repeater id = "clinicprogress" runat = "server">
<Itemtemplate>
<Tr>
<TD class = "k004" Height = "28">
<Table cellspacing = "0" cellpadding = "0" width = "390" border = "0">
<Tr>
<TD align = "center" width = "14" Height = "26"> <SPAN class = "bl012"> · </span> </TD>
<TD width = "331" Height = "26"> <SPAN class = "k012">
<A style = "color: #515050" href = '../news/news3.aspx? Moduleid = 500 & newsid = <% # databinder. eval (container. dataitem, "newsid") %> & Title = <% # system. web. httputility. urlencode (string) databinder. eval (container. dataitem, "newstitle") %> 'title = '<% # databinder. eval (container. dataitem, "newstitle") %> '>
<% # (String) databinder. eval (container. dataitem, "newstitle ")). substring (0, (string) databinder. eval (container. dataitem, "newstitle ")). length> 22? 22: (string) databinder. eval (container. dataitem, "newstitle"). Length) %>
</A>
</Span> </TD>
<TD width = "45"> <SPAN class = "k012"> [<% # databinder. eval (container. dataitem, "indate", "{0: Mm-dd}") %>] </span> </TD>
</Tr>
</Table>
</TD>
</Tr>
</Itemtemplate>
</ASP: repeater> </table>
<! -- International. Domestic clinical progress: end -->
// Define it in. aspx. Cs source code: and bind the data source to it
Protected system. Web. UI. webcontrols. Repeater rptanswers;
Daoservice subjectfac = new daoservice ();
Datatable dt = subjectfac. getlist_bypage ("*", sqlselect, "indate DESC, newsid DESC", 1, 1, 15, out pagecount, out rowcount );
If (DT! = NULL)
{
Rptanswers. datasource = DT;
Rptanswers. databind ();
}
Code Protected system. Web. UI. webcontrols. Repeater clinicprogress;
// International. Domestic clinical progress: 500
Private void binddata ()
{
Dt4 = mynews. getlist_bypage ("*", "modulecode = 500 and ispass = 1", "indate DESC, newsid DESC", 9, out pagecount, out rowscount );
Clinicprogress. datasource = dt4; // ds1.tables [0]. defaultview;
Clinicprogress. databind ();
}
Ii. usage (note)
(1) Data Binding
<% # Databinder. eval (container. dataitem, "newsid") %>
(2) You only need to place it in a proper position (for example, passing it as a hyperlink parameter)
<A href = 'expertdetails. aspx? Newsid = <% # databinder. eval (container. dataitem, "newsid") %>'
(3) data format conversion (for example, date format conversion)
<% # (Datetime) databinder. eval (container. dataitem, "editdate"). tostring ("mm-dd") %>
(4) the output length of a string can be limited (C # built-in functions can be used)
<% # (String) databinder. eval (container. dataitem, "newstitle ")). substring (0, (string) databinder. eval (container. dataitem, "newstitle ")). length> 10? 10: (string) databinder. eval (container. dataitem, "newstitle"). Length) %>
(5) Cyclic logic (container. itemindex indicates the number of cycles currently)
<% # (Container. itemindex + 1) % 3 = 0 )? "</Tr> <TD Height = '8' width = '000000' colspan = '13' bgcolor = '# ffff'> </TD> </tr> <tr> ": "" %>
(6) When passing Chinese characters between pages, use system. Web. httputility. urlencode to convert and place garbled characters.
Href = '../news/news3.aspx? Moduleid = 500 & newsid = <% # databinder. eval (container. dataitem, "newsid") %> & Title = <% # system. web. httputility. urlencode (string) databinder. eval (container. dataitem, "newstitle") %>'
Two questions: (vs2003 is used)
1.
When the href = "href =" "corresponding to <A> </A> In the code is enclosed in double quotation marks, the message" failed to open in design view. In the <% value %> fast, enclose values in different ways "... this prompt is not displayed if it is changed to single quotes.
<A href = 'recorddetailinfo. aspx? Newsid = <% # int32.parse (databinder. eval (container. dataitem, "newsid"). tostring () %> '> </a>
Sometimes there are such prompts .....
2. Sometimes vs2003 automatically adds some code for HTML (for example, adding a table to the outer layer) -- I just can't reproduce the problem.