<td width="504" bgColor="#ffffff" height="167" valign="top"><asp:datalist id="DataList1" runat="server" Width="504px">
<ItemTemplate>
<FONT face="宋体">
<TABLE id="Table1" cellSpacing="0" cellPadding="0" width="500" border="0">
<TR>
<TD>
<asp:Image id="Image1" runat="server" Width="4px" height="4" ImageUrl="Image/index-icon1.gif"></asp:Image>
</TD>
<TD width="367" height="10"><FONT face="宋体"><A title='<%# DataBinder.Eval(Container.DataItem,"Title")%>' href='javascript:viewNotice("Admin/Board_Popup.aspx?Seq=<%#DataBinder.Eval(Container.DataItem,"Seq")%>");'><font color="Black"><%# SubString(DataBinder.Eval(Container.DataItem,"Title").ToString(),28) %></font></A></FONT></TD>
<TD><FONT face="宋体"> </FONT>
<asp:Label id=Label1 runat="server" Width="100px" height="10" Text='<%# ChangeDate(DataBinder.Eval(Container.DataItem, "InputDate").ToString()) %>'>
</asp:Label></TD>
</TR>
</TABLE>
</FONT>
</ItemTemplate>
</asp:datalist></td>
在后台代码中添加:
DataList1.Height=ds.Tables[0].Rows.Count*27;
public string SubString(string str,int i)
{
string temp;
if(str.Length>i)
{
temp=str.Substring(0,i);
temp=temp+"
";
return temp;
}
else
return str;
}
public string ChangeDate(string date)
{
//string temp=Convert.ToDateTime(date).ToShortDateString();
string temp=DateTime.Parse(date).ToString("yyyyMMdd");
temp=temp.Substring(0,4)+"-"+temp.Substring(4,2)+"-"+temp.Substring(6,2);
return temp;
}
即设定DataList高度,这样就使得数据显示时有几条显示几条而且按固定高度显示。其他的数据绑定就和平常一样。
浙公网安备 33010602011771号