2011-09-05 40 views
0

我试图用工具提示绑定datagrid行。我应该在哪种情况下编写代码?该行创建的事件不会让我的数据绑定并返回空白。代码参考如下:如何在datagrid行上绑定工具提示?

protected void gdvActionItemView_RowCreated(object sender, GridViewRowEventArgs e) 
    { 


     e.Row.Cells[2].ToolTip = e.Row.Cells[2].Text; 
     if (e.Row.Cells[2].Text.Length > 100) 
     { 
      e.Row.Cells[2].Text.Substring(0, 100); 
     } 


    } 

请帮忙。

回答

0

找到了答案。它应该写在RowDataBound下。

1

你可以右键行数据绑定的事件,如:

protected void grdUserClone_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      for (int colIndex = 0; colIndex < e.Row.Cells.Count; colIndex++) 
      { 
       e.Row.Cells[colIndex].Attributes.Add("title", e.Row.Cells[colIndex].Text); 
      } 
     } 
    } 
相关问题