虽然只是DetailView例子,其他都一样呢,自己写定义函数,然后绑定下就Ok.
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="NewsID" DataSourceID="ObjectDataSource1" Height="50px"
Width="596px">
<Fields>
<asp:TemplateField HeaderText="NewsName" SortExpression="NewsName">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("NewsName") %>' Font-Bold='<%#IsBold() %>'></asp:Label>
<br />
<br />
<asp:TextBox ID="TextBox1" Text='<%#DisplayShort((SBSWEB.NewsRow)((System.Data.DataRowView)Container.DataItem).Row) %>' runat="server" Height="176px" TextMode="MultiLine" Width="287px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
protected string DisplayShort(SBSWEB.NewsRow newsrow)
{
if (newsrow.NewsDesc.Length > 20)
{
return newsrow.NewsDesc.Substring(0, 30).ToString() + "...";
}
else return newsrow.NewsDesc.ToString();
}
protected bool IsBold()
{
return true;
}