0

I have a link button which is a template field of my gridview. I need to set different text as tooltip of linkbutton in each row.My code not working,

 protected void Grid_course_RowDataBound(object sender, GridViewRowEventArgs e)
{


    connect con = new connect(date);
   if (e.Row.RowType == DataControlRowType.DataRow )
     { 
         LinkButton l = (LinkButton)e.Row.Cells[0].FindControl("Course_Name");
         IList<connect.Course> a = con.getCourse(l.Text);
         var result = string.Join(",", a[0].Course_Description__c);
         l.ToolTip = result.ToString();
         }
  }

It works only for first row.

user3065219
  • 45
  • 2
  • 12

1 Answers1

0

Create a dictionary with text of the link button as indexes and corresponding tooltip text as values.Retrieve the value using index in RowDataBound() event . Set it as tooltip.

protected void Grid_course_RowDataBound(object sender, GridViewRowEventArgs e)
{
    connect con = new connect(date);
    IList<connect.Courses> ob= con.getCoursedetails();
    Dictionary<string, string> example = new Dictionary<string, string>();
    for (int i = 0; i < ob.Count; i++)
        example.Add(ob[i].Name.ToString(), ob[i].Course_Description__c.ToString());//Setting Values to dictionary
    if (e.Row.RowType == DataControlRowType.DataRow )
     { 
         LinkButton l = (LinkButton)e.Row.Cells[0].FindControl("Course_Name");
         l.ToolTip = example[l.Text].ToString();//Retrieving values using index from dictiory.

     }
}
user3065219
  • 45
  • 2
  • 12