I have a GridView and a list of items in a ListBox. Excluding the first column in the GridView.
I want to tooltip each and every header with the corresponding item in the ListBox. I mean the tooltip for GridView2.Columns[i].HeaderText = ListBox.Items[i].Tostring().
Here is what I have tried:
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
for (int i = 1; i < GridView2.Columns.Count; i++)
{
String header = GridView2.Columns[i].HeaderText;
if (header.Length != 0)
{
e.Row.Cells[i].ToolTip = ListBox4.Items[i].ToString().Trim();
}
}
}
}
This is giving me an exception error: Index was out of range. Must be non-negative and less than the size of the collection.
Kindly help. Thank you.
Just suppose to use Cells[i+1] instead of Cells[i]