我正在使用一個帶有Asp:Label Control的templatecolumn的DataGrid。在設計頁面中,我使用了工具提示進行此控件,但在ItemDatabound事件中,它將檢查此標簽文本的字符數。如果角色小於40,我必須僅為該控件禁用工具提示..但我無法完成此任務。怎麽做?請幫幫我。提前致謝..
禁用控件的工具提示
最佳答案
假設標簽是DataGrid中的第一個單元格。如果沒有,您需要更改 Cells [0]
中的數字。
void R1_ItemDataBound(Object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
if(e.Item.Cells[0].Text.Length <= 40){
e.Item.Cells[0].Text = String.Empty;
}
}
}