Author: Afritxia
I have recently been writing a BBS project, when I display the topic list, I have encountered a problem. BBS_TOPIC data sheet structure definition is roughly below: Table BBS_Topic
(
TopicID Int Not Null Identity (1, 1) Primary Key,
Title nvarchar (40),
Author nvarchar (20),
PostDate DateTime Not Null Default getdate (),
Content NText,
Clicked Int Not Null Default 0,
Recount Int Not Null Default 0,
Lastreplyer nvarchar (20)
)
Below is some of the part of the listttopic.aspx file:
<% # DataBinder.eval (Container.DataItem, "Title")%>
<% # DataBinder.eval (Container.DataItem, "Author")%>
<% # DataBinder.eval (Container.DataItem, "Clicked")%>
<% # DataBinder.eval (Container.DataItem, "Recount")%>
<% IF ((int) (Container.eval ("Recount") == 0) {%>
----
<%} else {%>
<% # DataBinder.eval (Container.DataItem, "LastReplyer")%>
<%}%>
Itemtemplate>
ask: repeater>
The purpose of using the IF statement is to determine that the number of times the current post is 0, the LastReplyer is displayed as "----". When the number of reply to the current post is not 0, the name of the reply is displayed. However, such a practice is not enough. Similar warning compiler error messages in IE: CS0246: Can't find the type or namespace name "Container" (whether it is missing the USING directive or assembly reference?) Even if this error prompt, put all possible Namespaces all import into this file, or other error messages will still be prompted. As for why? It may be because DataBinder.eval and Container.DataItem are the members of the Repeater class. "<% #%>" Is "role" on the REPEATER, but the "if ... Else ..." statement is different, it is "role" on the entire page. This is like a partial variable directly in the global process. Of course, the beauty of the portal is δ 吭 ┑ 锞湟 锞湟 锞湟 锞湟 允 迪 迪 龉 龉 δ 埽? <% # (INT) (Container.DataItem, "Recount") == 0 )
? "----"
: DataBinder.eval (Container.DataItem, "LastReplyer")%> The problem is that for complex judgment processing, such a practice is quite difficult. <% # If ... else ...%> Why is this usage? Because <% #%> is equivalent to <% =%>, <% =%> is response.write (), then the previous judgment is coming: response.write (if ... Else ...); if Unexpected to determine the data in the Repeater, then the following method can be used: <% int _nIndex = 0;%>
<% # DataBinder.eval (Container.DataItem, "Title")%>
<% # DataBinder.eval (Container.DataItem, "Author")%>
<% # DataBinder.eval (Container.DataItem, "Clicked")%>
<% # DataBinder.eval (Container.DataItem, "Recount")%>
<%
INT NRECOUNT = (INT) ((dataView) _topicrepeater.datasource) .table.rows [_nIndex ] ["Recount"]);
// can also be divided into a few words to write
// DataView DV = (DataView) _topicrepeater.datasource;
// DV.Table.Rows [_NINDEX ] ["Recount"];
IF (NRECOUNT == 0) {%>
----
<%} else {%>
<% # DataBinder.eval (Container.DataItem, "LastReplyer")%>
<%}%>
Itemtemplate>
ask: repeater>