.AFR_Article_title
{
Font: Normal Bold 14px "Tahoma";
}
.AFR_CONTENTS
{
Font: Normal Normal 12px "Tahoma";
Line-height: 22px;
}
.AFR_CODE
{
FONT: NORMAL NORMAL 11PX "Courier New";
Line-height: 20px;
Width: 100%;
Background-color: #eeeeee;
Padding: 5 10 5 10;
}
.AFR_COMMON
{
COLOR: # 009900;
}
.AFR_STRING
{
Color: # eE0000;
}
.Af_server_side
{
Background-color: #fffdd;
}
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 above function can be achieved with a statement similar to the following (three-mesh operation): <% # ((int) ("rece) (Container.DataItem," Recount ")) == 0)?" ---- "
: DataBinder.eval (Container.DataItem, "LastReplyer")%>
The problem is that for complex judgment, 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>
Its basic idea is to get the data source of _topicrepeater (indicate: I use Dataset.Tables ["..."]. DefaultView. If you are using the data source of the data source binding the Repeater. Data source, then when you force the transformation of the Repeater.DataSource, you should pay a little attention) and return the current line of the table (ROWS [_NINDEX ]) finally determines whether the ReCount column is 0? In the initial time _NINDEX is assigned 0, then, in every itemtemplate, you will be added once. Its purpose, that is, let _nindex record "line" currently being visited. This method is also possible for DataGrid and DataList. Finally, this method is indeed valid when performing complex judgment binding data, but I don't recommend this practice! Because such an approach does not meet the object-oriented package characteristics, or, it is destroyed to make it transparent to complete the judgment function. The practice I recommend is to use "Custom User Control" to complete complex judgment binding tasks. Otte, I hope to help you ... Afritxia2003@yahoo.com.cn, afritxia@hotmail.com