Reputation: 361
Here is my code
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) {
// DataRow data = ((DataRowView)e.Row.DataItem).Row;
string ToolTipString = Convert.ToString(e.Row.Cells[2].Text);
e.Row.Cells[2].Attributes.Add("title", ToolTipString);
Label MyLabel = (Label)e.Row.FindControl("MyLabel");
if (ToolTipString.Length < 20) {
MyLabel.Text = ToolTipString;
}
else {
MyLabel.Text = String.Format("{0}...", ToolTipString.Substring(0, 17));
MyLabel.ToolTip = ToolTipString;
}
}
}
But Convert.ToString(e.Row.Cells[2].Text);
here always gives me "". Is there anything wrong in my code?
Upvotes: 2
Views: 8437
Reputation: 46
Usually this problem happens when the Column is hidden on the Grid. Two steps to solve it,
Instead of using Visible="false" use a css class for the bound field like this, ItemStyle-CssClass="Column_Hide"
Create Column_Hide in css file,
.Column_Hide
{
display: none;
}
Hopefully your problem will be solved
Upvotes: 2
Reputation:
Please use this code
var ToolTipString = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Column"));
Upvotes: 6