日期:2014-05-19  浏览次数:20352 次

很受伤,事件还是不起作用
public   void   DataGrid_ItemDataBound(object   sender,   System.Web.UI.WebControls.DataGridItemEventArgs   e)
{
      if(e.Item.DataSetIndex   !=   -1)
      {
          int   len=e.Item.Cells[1].Text.Length;
          if(len> 6)
          {
                e.Item.Cells[1].Text=e.Item.Cells[1].Text.Substring(0,6)+ "... ";
          }
      }
}

<asp:DataGrid   id= "DataGrid1 "   style= "Z-INDEX:   148;   LEFT:   16px;   POSITION:   absolute;   TOP:   352px "   runat= "server "   AutoGenerateColumns= "False "   OnItemDataBound= "DataGrid_ItemDataBound "   Width= "112px ">
      <Columns>
<asp:BoundColumn   Visible= "False "   DataField= "id "   HeaderText= "序号 "> </asp:BoundColumn>
<asp:HyperLinkColumn   Target= "_blank "   DataNavigateUrlField= "biaoti "   DataTextField= "biaoti "   HeaderText= "信息 "> </asp:HyperLinkColumn>
      </Columns>
</asp:DataGrid>


------解决方案--------------------
你单步调试一下,看看结果怎么样
------解决方案--------------------
不起作用?
设个断点调试一下先
------解决方案--------------------
e.Item.Cells[1].Text.Length 永远为0。你看来根本没有调试,查找BUG靠瞎猜测?否则只要10几秒钟你就能在断点中看到问题的根源。