【问题标题】:Setting tooltip to link button inside gridviewin.net将工具提示设置为 gridviewin.net 内的链接按钮
【发布时间】:2014-01-27 13:19:19
【问题描述】:

我有一个链接按钮,它是我的 gridview 的模板字段。我需要在每一行中设置不同的文本作为链接按钮的工具提示。我的代码不起作用,

 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();
         }
  }

它仅适用于第一行。

【问题讨论】:

  • 迭代时结果包含什么?
  • 我正在根据 gridview 中的一个字段从 salesforce 对象获取数据,该字段必须设置为工具提示。

标签: .net gridview rowdatabound


【解决方案1】:

创建一个字典,其中链接按钮的文本作为索引,相应的工具提示文本作为值。使用 RowDataBound() 事件中的索引检索值。将其设置为工具提示。

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.

     }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-22
    • 2016-09-29
    相关资源
    最近更新 更多