原来一直用GridView显示新闻标题列表及链接,因为GridView没有多列显示的功能,今天为了分两列显示新闻标题列表及链接,第一次用了DataList控件。
<asp:DataList ID="dlsYxcf" runat="server" DataSourceID="odsNews" Width="476px" RepeatColumns="2" RepeatDirection="Horizontal">
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="width: 238px">
<tr>
<td align="left" style="width: 190px; height: 14px" valign="middle">
<a href=shownewscontent.aspx?id=<%#Eval("id") %> target="_blank"><%#Eval("Title")%></a></td>
<td align="left" style="width: 48px; height: 14px; color: gray;" valign="middle">
<%#Eval("timeissue", "{0:d}")%></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
为了排版的整齐, <ItemTemplate>里用了表格,链接是这条语句:
<a href=shownewscontent.aspx?id=<%#Eval("id") %> target="_blank"><%#Eval("Title")%></a>
感觉太笨拙,应该有更好的方法。
数据源控件使用:ObjectDataSource
<asp:ObjectDataSource ID="odsNews" runat="server" SelectMethod="GetdstnewsTitle"
TypeName="Jobdatareader">
<SelectParameters>
<asp:Parameter DefaultValue="1001001001001001001001001001003" Name="classID" />
<asp:Parameter DefaultValue="20" Name="showTop" />
</SelectParameters>
</asp:ObjectDataSource>
浙公网安备 33010602011771号