I know how to use if statement in ItemTemplate, such as <%#Eval("ID")==0?"aaa":"bbb"%>
but, in my code, I also have a question.
I binded the data to repeater,but in the row one, the column"tuijian" is DBNull.
<asp:Repeater ID="repALL" runat="server">
<ItemTemplate>
<div class="table_style2">
<%
object objComID = ((System.Data.DataTable)repALL.DataSource).Rows[_nIndex]["ComID"];
object objJoinID = ((System.Data.DataTable)repALL.DataSource).Rows[_nIndex]["JoinID"];
_nIndex++;
if (objComID != System.DBNull.Value)
{ %>
<%# Convert.ToInt32(Eval("tuijian"))%>
<%}
else if (objJoinID != System.DBNull.Value)
{ %>
<%#Convert.ToInt16(Eval("ID"))%>
<%} %>
</div>
</ItemTemplate>
so the code is error on <%# Convert.ToInt32(Eval("tuijian"))%>
.
I rewrite the code like
<asp:Repeater ID="repALL" runat="server">
<ItemTemplate>
<div class="table_style2">
<%
object objComID = ((System.Data.DataTable)repALL.DataSource).Rows[_nIndex]["ComID"];
object objJoinID = ((System.Data.DataTable)repALL.DataSource).Rows[_nIndex]["JoinID"];
_nIndex++;
if (objComID != System.DBNull.Value)
{ %>
<%# Convert.ToInt32(Eval("ID"))%>
<%}
else if (objJoinID != System.DBNull.Value)
{ %>
<%#Convert.ToInt16(Eval("ID"))%>
<%} %>
</div>
</ItemTemplate>
the results can be showed in the web.
Aucun commentaire:
Enregistrer un commentaire