我用的模板显示数据,怎么没有显示到模板里呀?输出的汉字都跑到别的地方了,特乱.输出的汉字还是叠加的.密密麻麻在一起了.ASPX文件代码如下:
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:DataGrid id="DataGrid1" AutoGenerateColumns="False" Font-Size="10.5pt" style="Z-INDEX: 101;LEFT: 8px;WORD-BREAK: break-all;TOP: 8px;fPOSITION: absolute"
runat="server">
<Columns>
<asp:BoundColumn DataField="newsid">
<HeaderStyle Wrap="False" Width="5px"></HeaderStyle>
<ItemStyle Wrap="False" HorizontalAlign="Center" Width="50px" BackColor="#999999"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="newsheard">
<HeaderStyle Wrap="False" Width="150px"></HeaderStyle>
<ItemStyle Wrap="False" BackColor="#CCCCCC"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn SortExpression="newsbody">
<HeaderStyle Width="300px"></HeaderStyle>
<ItemTemplate>
<asp:Label style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 288px" runat="server" text='<%#changenewsbody(DataBinder.Eval(Container.DataItem,"newsbody"))%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="newstype">
<HeaderStyle Wrap="False" Width="20px"></HeaderStyle>
<ItemStyle Wrap="False" BackColor="#999999"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="newsviews">
<HeaderStyle Width="40px"></HeaderStyle>
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid></FONT>
</form>
CS文件代码:{
if(!IsPostBack)
{
datagridbind();
}

}
private void datagridbind()
{
SqlConnection sqlcon=new SqlConnection("server=localhost;uid=sa;pwd=;database=mydatabase;");
sqlcon.Open();
SqlCommand sqlcmd=new SqlCommand("(select newsid,newsheard,newstype,substring(newsbody,1,300) as newsbody,newstime,newsviews from newstable)",sqlcon);
SqlDataAdapter dapubs=new SqlDataAdapter();
dapubs.SelectCommand=sqlcmd;
DataSet dspubs=new DataSet();
dapubs.Fill(dspubs);
DataGrid1.DataSource=dspubs.Tables[0].DefaultView;
DataGrid1.DataBind();
} public  string changenewsbody(object e) {

string a=(string)e;
if(a.Length>=499)
{
string tmp="............";
tmp+=e;
return a;
}
else
{
return a;
}
}

解决方案 »

  1.   

    改为下面这样试试
    text='<%#changenewsbody(Container.DataItem)%>'
    public  string changenewsbody(System.Data.DataRowView r) {

    string a=r("newsbody");
    if(a.Length>=499)
    {
    string tmp="............";
    tmp+=e;
    return a;
    }
    else
    {
    return a;
    }
    }
      

  2.   

    还是不行呀.提示:编译器错误信息: CS1502: 与“WebApplication2.view.changenewsbody(System.Data.DataRowView)”最匹配的重载方法具有一些无效参数好像不是datarowview类型的.是object型
      

  3.   

    知道了,大家以后注意,模板里加的LABEL不要加STYLE和CSS样式.