使用DataList
<asp:datalist id="DataList1" runat="server" Width="90%">
<HeaderTemplate>
<table border="0" width="100%" bordercolor="#FF0000" align="center">
<tr>
<td width="7%" nowrap bgcolor="dbdbdb" class="p1" align="center">编号</td>
<td width="29%" nowrap bgcolor="dbdbdb" class="p1" align="center">主题</td>
<td width="15%" nowrap bgcolor="dbdbdb" class="p1" align="center">作者</td>
<td width="19%" nowrap bgcolor="dbdbdb" class="p1" align="center">发表时间</td>
<td width="15%" nowrap bgcolor="dbdbdb" class="p1" align="center">回复/浏览次数</td>
<td width="15%" nowrap bgcolor="dbdbdb" class="p1" align="center">最后回复</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table border="0" width="100%" bordercolor="#FF0000" align="center">
<tr>
<td width="7%" class="p1" align="center" bgcolor="f7f7f7"> <%# Container.ItemIndex+1 %></td>
<td width="29%" class="p1" bgcolor="f7f7f7"> <a href='Detail.aspx?RootID=<%# DataBinder.Eval(Container.DataItem,"ReferID") %>' target="_self"><font color="#000000"><%# DataBinder.Eval(Container.DataItem,"Subject") %></font></a></td>
<td width="15%" class="p1" bgcolor="f7f7f7"> <%# DataBinder.Eval(Container.DataItem,"Name") %></td>
<td width="19%" class="p1" align="center" bgcolor="f7f7f7"> <%# DataBinder.Eval(Container.DataItem,"PostDate") %></td>
<td width="15%" class="p1" align="center" bgcolor="f7f7f7"> <%# DataBinder.Eval(Container.DataItem,"Child") %>/<%# DataBinder.Eval(Container.DataItem,"Hits") %></td>
<td width="15%" class="p1" align="center" bgcolor="f7f7f7"> <%# GetLastReplayName(DataBinder.Eval(Container.DataItem,"LastPost").ToString()) %></td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
<asp:datalist id="DataList1" runat="server" Width="90%">
<HeaderTemplate>
<table border="0" width="100%" bordercolor="#FF0000" align="center">
<tr>
<td width="7%" nowrap bgcolor="dbdbdb" class="p1" align="center">编号</td>
<td width="29%" nowrap bgcolor="dbdbdb" class="p1" align="center">主题</td>
<td width="15%" nowrap bgcolor="dbdbdb" class="p1" align="center">作者</td>
<td width="19%" nowrap bgcolor="dbdbdb" class="p1" align="center">发表时间</td>
<td width="15%" nowrap bgcolor="dbdbdb" class="p1" align="center">回复/浏览次数</td>
<td width="15%" nowrap bgcolor="dbdbdb" class="p1" align="center">最后回复</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table border="0" width="100%" bordercolor="#FF0000" align="center">
<tr>
<td width="7%" class="p1" align="center" bgcolor="f7f7f7"> <%# Container.ItemIndex+1 %></td>
<td width="29%" class="p1" bgcolor="f7f7f7"> <a href='Detail.aspx?RootID=<%# DataBinder.Eval(Container.DataItem,"ReferID") %>' target="_self"><font color="#000000"><%# DataBinder.Eval(Container.DataItem,"Subject") %></font></a></td>
<td width="15%" class="p1" bgcolor="f7f7f7"> <%# DataBinder.Eval(Container.DataItem,"Name") %></td>
<td width="19%" class="p1" align="center" bgcolor="f7f7f7"> <%# DataBinder.Eval(Container.DataItem,"PostDate") %></td>
<td width="15%" class="p1" align="center" bgcolor="f7f7f7"> <%# DataBinder.Eval(Container.DataItem,"Child") %>/<%# DataBinder.Eval(Container.DataItem,"Hits") %></td>
<td width="15%" class="p1" align="center" bgcolor="f7f7f7"> <%# GetLastReplayName(DataBinder.Eval(Container.DataItem,"LastPost").ToString()) %></td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
仔细看看!
一种是用dataset
datasetName.Table["tablename"].DefaultView来邦定
另外一种是用datareader
返回一个datareader后
用一个对象数组来存组数据
因为arraylist是从IList接口派生的,所以也能用来邦定